Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridgeTest.java

Issue 1524293002: [Offline pages] Expose offline pages URL related methods in java code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab-android
Patch Set: Making the new method visible for testing Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.offlinepages; 5 package org.chromium.chrome.browser.offlinepages;
6 6
7 import android.test.suitebuilder.annotation.MediumTest; 7 import android.test.suitebuilder.annotation.SmallTest;
8 8
9 import org.chromium.base.ThreadUtils; 9 import org.chromium.base.ThreadUtils;
10 import org.chromium.chrome.browser.ChromeActivity; 10 import org.chromium.chrome.browser.ChromeActivity;
11 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.DeletePageCall back; 11 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.DeletePageCall back;
12 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.OfflinePageMod elObserver; 12 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.OfflinePageMod elObserver;
13 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.SavePageCallba ck; 13 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.SavePageCallba ck;
14 import org.chromium.chrome.browser.profiles.Profile; 14 import org.chromium.chrome.browser.profiles.Profile;
15 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 15 import org.chromium.chrome.test.ChromeActivityTestCaseBase;
16 import org.chromium.chrome.test.util.TestHttpServerClient; 16 import org.chromium.chrome.test.util.TestHttpServerClient;
17 import org.chromium.components.bookmarks.BookmarkId; 17 import org.chromium.components.bookmarks.BookmarkId;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 }); 63 });
64 assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)); 64 assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS));
65 } 65 }
66 66
67 @Override 67 @Override
68 public void startMainActivity() throws InterruptedException { 68 public void startMainActivity() throws InterruptedException {
69 startMainActivityOnBlankPage(); 69 startMainActivityOnBlankPage();
70 } 70 }
71 71
72 @MediumTest 72 @SmallTest
73 public void testLoadOfflinePagesWhenEmpty() throws Exception { 73 public void testLoadOfflinePagesWhenEmpty() throws Exception {
74 List<OfflinePageItem> offlinePages = getAllPages(); 74 List<OfflinePageItem> offlinePages = getAllPages();
75 assertEquals("Offline pages count incorrect.", 0, offlinePages.size()); 75 assertEquals("Offline pages count incorrect.", 0, offlinePages.size());
76 } 76 }
77 77
78 @MediumTest 78 @SmallTest
79 public void testAddOfflinePageAndLoad() throws Exception { 79 public void testAddOfflinePageAndLoad() throws Exception {
80 loadUrl(TEST_PAGE); 80 loadUrl(TEST_PAGE);
81 savePage(SavePageResult.SUCCESS, TEST_PAGE); 81 savePage(SavePageResult.SUCCESS, TEST_PAGE);
82 List<OfflinePageItem> allPages = getAllPages(); 82 List<OfflinePageItem> allPages = getAllPages();
83 OfflinePageItem offlinePage = allPages.get(0); 83 OfflinePageItem offlinePage = allPages.get(0);
84 assertEquals("Offline pages count incorrect.", 1, allPages.size()); 84 assertEquals("Offline pages count incorrect.", 1, allPages.size());
85 assertEquals("Offline page item url incorrect.", TEST_PAGE, offlinePage. getUrl()); 85 assertEquals("Offline page item url incorrect.", TEST_PAGE, offlinePage. getUrl());
86 assertEquals("Offline page item bookmark ID incorrect.", BOOKMARK_ID, 86 assertEquals("Offline page item bookmark ID incorrect.", BOOKMARK_ID,
87 offlinePage.getBookmarkId()); 87 offlinePage.getBookmarkId());
88 assertTrue("Offline page item offline file url doesn't start properly.", 88 assertTrue("Offline page item offline file url doesn't start properly.",
89 offlinePage.getOfflineUrl().startsWith("file:///")); 89 offlinePage.getOfflineUrl().startsWith("file:///"));
90 assertTrue("Offline page item offline file doesn't have the right name." , 90 assertTrue("Offline page item offline file doesn't have the right name." ,
91 offlinePage.getOfflineUrl().endsWith(".mhtml")); 91 offlinePage.getOfflineUrl().endsWith(".mhtml"));
92 assertTrue("Offline page item offline file doesn't have the right name." , 92 assertTrue("Offline page item offline file doesn't have the right name." ,
93 offlinePage.getOfflineUrl().contains("About")); 93 offlinePage.getOfflineUrl().contains("About"));
94 94
95 // We don't care about the exact file size of the mhtml file: 95 // We don't care about the exact file size of the mhtml file:
96 // - exact file size is not something that the end user sees or cares ab out 96 // - exact file size is not something that the end user sees or cares ab out
97 // - exact file size can vary based on external factors (i.e. see crbug. com/518758) 97 // - exact file size can vary based on external factors (i.e. see crbug. com/518758)
98 // - verification of contents of the resulting mhtml file should be cove red by mhtml 98 // - verification of contents of the resulting mhtml file should be cove red by mhtml
99 // serialization tests (i.e. save_page_browsertest.cc) 99 // serialization tests (i.e. save_page_browsertest.cc)
100 // - we want to avoid overtesting and artificially requiring specific fo rmatting and/or 100 // - we want to avoid overtesting and artificially requiring specific fo rmatting and/or
101 // implementation choices in the mhtml serialization code 101 // implementation choices in the mhtml serialization code
102 // OTOH, it still seems useful to assert that the file is not empty and that its size is in 102 // OTOH, it still seems useful to assert that the file is not empty and that its size is in
103 // the right ballpark. 103 // the right ballpark.
104 long size = offlinePage.getFileSize(); 104 long size = offlinePage.getFileSize();
105 assertTrue("Offline page item size is incorrect: " + size, 600 < size && size < 800); 105 assertTrue("Offline page item size is incorrect: " + size, 600 < size && size < 800);
106 } 106 }
107 107
108 @MediumTest 108 @SmallTest
109 public void testMarkPageAccessed() throws Exception { 109 public void testMarkPageAccessed() throws Exception {
110 loadUrl(TEST_PAGE); 110 loadUrl(TEST_PAGE);
111 savePage(SavePageResult.SUCCESS, TEST_PAGE); 111 savePage(SavePageResult.SUCCESS, TEST_PAGE);
112 OfflinePageItem offlinePage = mOfflinePageBridge.getPageByBookmarkId(BOO KMARK_ID); 112 OfflinePageItem offlinePage = mOfflinePageBridge.getPageByBookmarkId(BOO KMARK_ID);
113 assertNotNull("Offline page should be available, but it is not.", offlin ePage); 113 assertNotNull("Offline page should be available, but it is not.", offlin ePage);
114 assertEquals("Offline page access count should be 0.", 0, offlinePage.ge tAccessCount()); 114 assertEquals("Offline page access count should be 0.", 0, offlinePage.ge tAccessCount());
115 115
116 markPageAccessed(BOOKMARK_ID, 1); 116 markPageAccessed(BOOKMARK_ID, 1);
117 } 117 }
118 118
119 @MediumTest 119 @SmallTest
120 public void testGetPageByBookmarkId() throws Exception { 120 public void testGetPageByBookmarkId() throws Exception {
121 loadUrl(TEST_PAGE); 121 loadUrl(TEST_PAGE);
122 savePage(SavePageResult.SUCCESS, TEST_PAGE); 122 savePage(SavePageResult.SUCCESS, TEST_PAGE);
123 OfflinePageItem offlinePage = mOfflinePageBridge.getPageByBookmarkId(BOO KMARK_ID); 123 OfflinePageItem offlinePage = mOfflinePageBridge.getPageByBookmarkId(BOO KMARK_ID);
124 assertEquals("Offline page item url incorrect.", TEST_PAGE, offlinePage. getUrl()); 124 assertEquals("Offline page item url incorrect.", TEST_PAGE, offlinePage. getUrl());
125 assertEquals("Offline page item bookmark ID incorrect.", BOOKMARK_ID, 125 assertEquals("Offline page item bookmark ID incorrect.", BOOKMARK_ID,
126 offlinePage.getBookmarkId()); 126 offlinePage.getBookmarkId());
127 assertTrue("Offline page item offline file url doesn't start properly.", 127 assertTrue("Offline page item offline file url doesn't start properly.",
128 offlinePage.getOfflineUrl().startsWith("file:///")); 128 offlinePage.getOfflineUrl().startsWith("file:///"));
129 assertTrue("Offline page item offline file doesn't have the right name." , 129 assertTrue("Offline page item offline file doesn't have the right name." ,
130 offlinePage.getOfflineUrl().endsWith(".mhtml")); 130 offlinePage.getOfflineUrl().endsWith(".mhtml"));
131 assertTrue("Offline page item offline file doesn't have the right name." , 131 assertTrue("Offline page item offline file doesn't have the right name." ,
132 offlinePage.getOfflineUrl().contains("About")); 132 offlinePage.getOfflineUrl().contains("About"));
133 133
134 assertNull("Offline page is not supposed to exist", 134 assertNull("Offline page is not supposed to exist",
135 mOfflinePageBridge.getPageByBookmarkId(new BookmarkId(-42, Bookm arkType.NORMAL))); 135 mOfflinePageBridge.getPageByBookmarkId(new BookmarkId(-42, Bookm arkType.NORMAL)));
136 } 136 }
137 137
138 @MediumTest 138 @SmallTest
139 public void testDeleteOfflinePage() throws Exception { 139 public void testDeleteOfflinePage() throws Exception {
140 deletePage(BOOKMARK_ID, DeletePageResult.NOT_FOUND); 140 deletePage(BOOKMARK_ID, DeletePageResult.NOT_FOUND);
141 loadUrl(TEST_PAGE); 141 loadUrl(TEST_PAGE);
142 savePage(SavePageResult.SUCCESS, TEST_PAGE); 142 savePage(SavePageResult.SUCCESS, TEST_PAGE);
143 assertNotNull("Offline page should be available, but it is not.", 143 assertNotNull("Offline page should be available, but it is not.",
144 mOfflinePageBridge.getPageByBookmarkId(BOOKMARK_ID)); 144 mOfflinePageBridge.getPageByBookmarkId(BOOKMARK_ID));
145 deletePage(BOOKMARK_ID, DeletePageResult.SUCCESS); 145 deletePage(BOOKMARK_ID, DeletePageResult.SUCCESS);
146 assertNull("Offline page should be gone, but it is available.", 146 assertNull("Offline page should be gone, but it is available.",
147 mOfflinePageBridge.getPageByBookmarkId(BOOKMARK_ID)); 147 mOfflinePageBridge.getPageByBookmarkId(BOOKMARK_ID));
148 } 148 }
149 149
150 @SmallTest
151 public void testGetOfflineUrlForOnlineUrl() throws Exception {
152 loadUrl(TEST_PAGE);
153 savePage(SavePageResult.SUCCESS, TEST_PAGE);
154 OfflinePageItem offlinePage = mOfflinePageBridge.getPageByBookmarkId(BOO KMARK_ID);
155 assertEquals("We should get the same offline URL, when querying using on line URL",
156 offlinePage.getOfflineUrl(),
157 mOfflinePageBridge.getOfflineUrlForOnlineUrl(offlinePage.getUrl( )));
158 }
159
160 @SmallTest
161 public void testIsOfflniePageUrl() throws Exception {
newt (away) 2016/01/05 22:40:41 s/Offlnie/Offline/
fgorski 2016/01/07 17:12:49 Done.
162 loadUrl(TEST_PAGE);
163 savePage(SavePageResult.SUCCESS, TEST_PAGE);
164 OfflinePageItem offlinePage = mOfflinePageBridge.getPageByBookmarkId(BOO KMARK_ID);
165 assertTrue("Offline URL of an offline page should clearly be an offline page URL",
166 mOfflinePageBridge.isOfflinePageUrl(offlinePage.getOfflineUrl()) );
167 assertFalse("Online URL of an offline page should not be an offline page URL",
168 mOfflinePageBridge.isOfflinePageUrl(offlinePage.getUrl()));
169 }
170
150 private void savePage(final int expectedResult, final String expectedUrl) 171 private void savePage(final int expectedResult, final String expectedUrl)
151 throws InterruptedException { 172 throws InterruptedException {
152 final Semaphore semaphore = new Semaphore(0); 173 final Semaphore semaphore = new Semaphore(0);
153 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 174 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
154 @Override 175 @Override
155 public void run() { 176 public void run() {
156 assertNotNull("Tab is null", getActivity().getActivityTab()); 177 assertNotNull("Tab is null", getActivity().getActivityTab());
157 assertEquals("URL does not match requested.", TEST_PAGE, 178 assertEquals("URL does not match requested.", TEST_PAGE,
158 getActivity().getActivityTab().getUrl()); 179 getActivity().getActivityTab().getUrl());
159 assertNotNull("WebContents is null", 180 assertNotNull("WebContents is null",
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 result.add(item); 244 result.add(item);
224 } 245 }
225 246
226 semaphore.release(); 247 semaphore.release();
227 } 248 }
228 }); 249 });
229 assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)); 250 assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS));
230 return result; 251 return result;
231 } 252 }
232 } 253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698