@Test public void runTest_1() { List<Session> sessionlist; Session session_1; session_1 = mock(Session.class); sessionlist = new ArrayList<Session>(); sessionlist.add(session_1); Mockito.when((TraceDirectoryResult) tracedata.getTraceresult()).thenReturn(dirdata); Mockito.when(dirdata.getTraceResultType()).thenReturn(TraceResultType.TRACE_DIRECTORY); Mockito.when(dirdata.getDeviceScreenSizeX()).thenReturn(480); Mockito.when(dirdata.getDeviceScreenSizeY()).thenReturn(800); ImageSizeImpl = (ImageSizeImpl) context.getBean("imageSize"); result = ImageSizeImpl.runTest(tracedata); assertEquals( "Images that are not correctly sized for mobile can cause extreme delays in rendering. Before delivering content to a mobile, resize it to fit the available area.", result.getAboutText()); assertEquals("Resize Images for Mobile", result.getDetailTitle()); assertEquals("File Download: Resize Images for Mobile", result.getOverviewTitle()); assertEquals( "Your trace passes. There are no image files that are 110% larger than the area specified for them.", result.getResultText()); assertEquals("IMAGE_SIZE", result.getBestPracticeType().toString()); assertEquals("PASS", result.getResultType().toString()); }
@Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { mImageFoundInHtmlOrCss = false; ImageSizeResult result = new ImageSizeResult(); List<ImageSizeEntry> entrylist = new ArrayList<ImageSizeEntry>(); int deviceScreenSizeX = 528; int deviceScreenSizeY = 880; if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { TraceDirectoryResult dirdata = (TraceDirectoryResult) tracedata.getTraceresult(); deviceScreenSizeX = (dirdata.getDeviceScreenSizeX() * 110) / 100; deviceScreenSizeY = (dirdata.getDeviceScreenSizeY() * 110) / 100; } for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastReq = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastReq = req; } if (req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getContentType().contains("image/")) { boolean isBigSize = false; List<HtmlImage> htmlImageList = checkThisImageInAllHTMLOrCSS(session, req); if (mImageFoundInHtmlOrCss) { mImageFoundInHtmlOrCss = false; if (!htmlImageList.isEmpty()) { for (int index = 0; index < htmlImageList.size(); index++) { HtmlImage htmlImage = htmlImageList.get(index); isBigSize = compareDownloadedImgSizeWithStdImageSize(req, htmlImage, deviceScreenSizeX, deviceScreenSizeY, session); if (isBigSize) { break; } } } else { isBigSize = compareDownloadedImgSizeWithStdImageSize(req, null, deviceScreenSizeX, deviceScreenSizeY, session); } if (isBigSize) { entrylist.add(new ImageSizeEntry(req, lastReq, session.getDomainName())); } } } } } result.setDeviceScreenSizeRangeX(deviceScreenSizeX); result.setDeviceScreenSizeRangeY(deviceScreenSizeY); result.setResults(entrylist); String text = ""; if (entrylist.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, entrylist.size()); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), entrylist.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportNumberOfLargeImages(exportNumberOfLargeImages); return result; }
ImageSizeImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { mImageFoundInHtmlOrCss = false; ImageSizeResult result = new ImageSizeResult(); List<ImageSizeEntry> entrylist = new ArrayList<ImageSizeEntry>(); int deviceScreenSizeX = 528; int deviceScreenSizeY = 880; if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { TraceDirectoryResult dirdata = (TraceDirectoryResult) tracedata.getTraceresult(); deviceScreenSizeX = (dirdata.getDeviceScreenSizeX() * 110) / 100; deviceScreenSizeY = (dirdata.getDeviceScreenSizeY() * 110) / 100; } for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastReq = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastReq = req; } if (req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getContentType().contains("image/")) { boolean isBigSize = false; List<HtmlImage> htmlImageList = checkThisImageInAllHTMLOrCSS(session, req); if (mImageFoundInHtmlOrCss) { mImageFoundInHtmlOrCss = false; if (!htmlImageList.isEmpty()) { for (int index = 0; index < htmlImageList.size(); index++) { HtmlImage htmlImage = htmlImageList.get(index); isBigSize = compareDownloadedImgSizeWithStdImageSize(req, htmlImage, deviceScreenSizeX, deviceScreenSizeY, session); if (isBigSize) { break; } } } else { isBigSize = compareDownloadedImgSizeWithStdImageSize(req, null, deviceScreenSizeX, deviceScreenSizeY, session); } if (isBigSize) { entrylist.add(new ImageSizeEntry(req, lastReq, session.getDomainName())); } } } } } result.setDeviceScreenSizeRangeX(deviceScreenSizeX); result.setDeviceScreenSizeRangeY(deviceScreenSizeY); result.setResults(entrylist); String text = ""; if (entrylist.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, entrylist.size()); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), entrylist.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportNumberOfLargeImages(exportNumberOfLargeImages); return result; } }
ImageSizeImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { mImageFoundInHtmlOrCss = false; ImageSizeResult result = new ImageSizeResult(); List<ImageSizeEntry> entrylist = new ArrayList<ImageSizeEntry>(); int deviceScreenSizeX = 528; int deviceScreenSizeY = 880; if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { TraceDirectoryResult dirdata = (TraceDirectoryResult) tracedata.getTraceresult(); deviceScreenSizeX = (dirdata.getDeviceScreenSizeX() * 110) / 100; deviceScreenSizeY = (dirdata.getDeviceScreenSizeY() * 110) / 100; } for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastReq = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastReq = req; } if (req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getContentType().contains("image/")) { boolean isBigSize = false; List<HtmlImage> htmlImageList = checkThisImageInAllHTMLOrCSS(session, req); if (mImageFoundInHtmlOrCss) { mImageFoundInHtmlOrCss = false; if (!htmlImageList.isEmpty()) { for (int index = 0; index < htmlImageList.size(); index++) { HtmlImage htmlImage = htmlImageList.get(index); isBigSize = compareDownloadedImgSizeWithStdImageSize(req, htmlImage, deviceScreenSizeX, deviceScreenSizeY, session); if (isBigSize) { break; } } } else { isBigSize = compareDownloadedImgSizeWithStdImageSize(req, null, deviceScreenSizeX, deviceScreenSizeY, session); } if (isBigSize) { entrylist.add(new ImageSizeEntry(req, lastReq, session.getDomainName())); } } } } } result.setDeviceScreenSizeRangeX(deviceScreenSizeX); result.setDeviceScreenSizeRangeY(deviceScreenSizeY); result.setResults(entrylist); String text = ""; if (entrylist.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, entrylist.size()); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), entrylist.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportNumberOfLargeImages(exportNumberOfLargeImages); return result; }  }
ImageSizeImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { mImageFoundInHtmlOrCss = false; ImageSizeResult result = new ImageSizeResult(); List<ImageSizeEntry> entrylist = new ArrayList<ImageSizeEntry>(); int deviceScreenSizeX = 528; int deviceScreenSizeY = 880; if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { TraceDirectoryResult dirdata = (TraceDirectoryResult) tracedata.getTraceresult(); deviceScreenSizeX = (dirdata.getDeviceScreenSizeX() * 110) / 100; deviceScreenSizeY = (dirdata.getDeviceScreenSizeY() * 110) / 100; } for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastReq = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastReq = req; } if (req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getContentType().contains("image/")) { boolean isBigSize = false; List<HtmlImage> htmlImageList = checkThisImageInAllHTMLOrCSS(session, req); if (mImageFoundInHtmlOrCss) { mImageFoundInHtmlOrCss = false; if (!htmlImageList.isEmpty()) { for (int index = 0; index < htmlImageList.size(); index++) { HtmlImage htmlImage = htmlImageList.get(index); isBigSize = compareDownloadedImgSizeWithStdImageSize(req, htmlImage, deviceScreenSizeX, deviceScreenSizeY, session); if (isBigSize) { break; } } } else { isBigSize = compareDownloadedImgSizeWithStdImageSize(req, null, deviceScreenSizeX, deviceScreenSizeY, session); } if (isBigSize) { entrylist.add(new ImageSizeEntry(req, lastReq, session.getDomainName())); } } } } } result.setDeviceScreenSizeRangeX(deviceScreenSizeX); result.setDeviceScreenSizeRangeY(deviceScreenSizeY); result.setResults(entrylist); String text = ""; if (entrylist.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, entrylist.size()); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), entrylist.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportNumberOfLargeImages(exportNumberOfLargeImages); return result; }  @Autowired void setReqhelper(IHttpRequestResponseHelper helper); @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata); }
ImageSizeImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { mImageFoundInHtmlOrCss = false; ImageSizeResult result = new ImageSizeResult(); List<ImageSizeEntry> entrylist = new ArrayList<ImageSizeEntry>(); int deviceScreenSizeX = 528; int deviceScreenSizeY = 880; if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { TraceDirectoryResult dirdata = (TraceDirectoryResult) tracedata.getTraceresult(); deviceScreenSizeX = (dirdata.getDeviceScreenSizeX() * 110) / 100; deviceScreenSizeY = (dirdata.getDeviceScreenSizeY() * 110) / 100; } for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastReq = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastReq = req; } if (req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getContentType().contains("image/")) { boolean isBigSize = false; List<HtmlImage> htmlImageList = checkThisImageInAllHTMLOrCSS(session, req); if (mImageFoundInHtmlOrCss) { mImageFoundInHtmlOrCss = false; if (!htmlImageList.isEmpty()) { for (int index = 0; index < htmlImageList.size(); index++) { HtmlImage htmlImage = htmlImageList.get(index); isBigSize = compareDownloadedImgSizeWithStdImageSize(req, htmlImage, deviceScreenSizeX, deviceScreenSizeY, session); if (isBigSize) { break; } } } else { isBigSize = compareDownloadedImgSizeWithStdImageSize(req, null, deviceScreenSizeX, deviceScreenSizeY, session); } if (isBigSize) { entrylist.add(new ImageSizeEntry(req, lastReq, session.getDomainName())); } } } } } result.setDeviceScreenSizeRangeX(deviceScreenSizeX); result.setDeviceScreenSizeRangeY(deviceScreenSizeY); result.setResults(entrylist); String text = ""; if (entrylist.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, entrylist.size()); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), entrylist.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportNumberOfLargeImages(exportNumberOfLargeImages); return result; }  @Autowired void setReqhelper(IHttpRequestResponseHelper helper); @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata);  }