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

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

Issue 1694863003: Refactor the offline page storage to include client namespace and id. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address changes Created 4 years, 9 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.content.Context; 7 import android.content.Context;
8 import android.os.Environment; 8 import android.os.Environment;
9 import android.test.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 102
103 @SmallTest 103 @SmallTest
104 public void testAddOfflinePageAndLoad() throws Exception { 104 public void testAddOfflinePageAndLoad() throws Exception {
105 loadUrl(mTestPage); 105 loadUrl(mTestPage);
106 savePage(SavePageResult.SUCCESS, mTestPage); 106 savePage(SavePageResult.SUCCESS, mTestPage);
107 List<OfflinePageItem> allPages = getAllPages(); 107 List<OfflinePageItem> allPages = getAllPages();
108 OfflinePageItem offlinePage = allPages.get(0); 108 OfflinePageItem offlinePage = allPages.get(0);
109 assertEquals("Offline pages count incorrect.", 1, allPages.size()); 109 assertEquals("Offline pages count incorrect.", 1, allPages.size());
110 assertEquals("Offline page item url incorrect.", mTestPage, offlinePage. getUrl()); 110 assertEquals("Offline page item url incorrect.", mTestPage, offlinePage. getUrl());
111 assertEquals("Offline page item bookmark ID incorrect.", BOOKMARK_ID,
112 offlinePage.getBookmarkId());
113 assertTrue("Offline page item offline file url doesn't start properly.", 111 assertTrue("Offline page item offline file url doesn't start properly.",
114 offlinePage.getOfflineUrl().startsWith("file:///")); 112 offlinePage.getOfflineUrl().startsWith("file:///"));
115 assertTrue("Offline page item offline file doesn't have the right name." , 113 assertTrue("Offline page item offline file doesn't have the right name." ,
116 offlinePage.getOfflineUrl().endsWith(".mhtml")); 114 offlinePage.getOfflineUrl().endsWith(".mhtml"));
117 assertTrue("Offline page item offline file doesn't have the right name." , 115 assertTrue("Offline page item offline file doesn't have the right name." ,
118 offlinePage.getOfflineUrl().contains("About")); 116 offlinePage.getOfflineUrl().contains("About"));
119 117
120 // We don't care about the exact file size of the mhtml file: 118 // We don't care about the exact file size of the mhtml file:
121 // - exact file size is not something that the end user sees or cares ab out 119 // - exact file size is not something that the end user sees or cares ab out
122 // - exact file size can vary based on external factors (i.e. see crbug. com/518758) 120 // - exact file size can vary based on external factors (i.e. see crbug. com/518758)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 218 }
221 }); 219 });
222 } 220 }
223 221
224 @SmallTest 222 @SmallTest
225 public void testGetPageByBookmarkId() throws Exception { 223 public void testGetPageByBookmarkId() throws Exception {
226 loadUrl(mTestPage); 224 loadUrl(mTestPage);
227 savePage(SavePageResult.SUCCESS, mTestPage); 225 savePage(SavePageResult.SUCCESS, mTestPage);
228 OfflinePageItem offlinePage = mOfflinePageBridge.getPageByBookmarkId(BOO KMARK_ID); 226 OfflinePageItem offlinePage = mOfflinePageBridge.getPageByBookmarkId(BOO KMARK_ID);
229 assertEquals("Offline page item url incorrect.", mTestPage, offlinePage. getUrl()); 227 assertEquals("Offline page item url incorrect.", mTestPage, offlinePage. getUrl());
230 assertEquals("Offline page item bookmark ID incorrect.", BOOKMARK_ID,
231 offlinePage.getBookmarkId());
232 assertTrue("Offline page item offline file url doesn't start properly.", 228 assertTrue("Offline page item offline file url doesn't start properly.",
233 offlinePage.getOfflineUrl().startsWith("file:///")); 229 offlinePage.getOfflineUrl().startsWith("file:///"));
234 assertTrue("Offline page item offline file doesn't have the right name." , 230 assertTrue("Offline page item offline file doesn't have the right name." ,
235 offlinePage.getOfflineUrl().endsWith(".mhtml")); 231 offlinePage.getOfflineUrl().endsWith(".mhtml"));
236 assertTrue("Offline page item offline file doesn't have the right name." , 232 assertTrue("Offline page item offline file doesn't have the right name." ,
237 offlinePage.getOfflineUrl().contains("About")); 233 offlinePage.getOfflineUrl().contains("About"));
238 234
239 assertNull("Offline page is not supposed to exist", 235 assertNull("Offline page is not supposed to exist",
240 mOfflinePageBridge.getPageByBookmarkId(new BookmarkId(-42, Bookm arkType.NORMAL))); 236 mOfflinePageBridge.getPageByBookmarkId(new BookmarkId(-42, Bookm arkType.NORMAL)));
241 } 237 }
(...skipping 28 matching lines...) Expand all
270 public void run() { 266 public void run() {
271 assertNotNull("Tab is null", getActivity().getActivityTab()); 267 assertNotNull("Tab is null", getActivity().getActivityTab());
272 assertEquals("URL does not match requested.", mTestPage, 268 assertEquals("URL does not match requested.", mTestPage,
273 getActivity().getActivityTab().getUrl()); 269 getActivity().getActivityTab().getUrl());
274 assertNotNull("WebContents is null", 270 assertNotNull("WebContents is null",
275 getActivity().getActivityTab().getWebContents()); 271 getActivity().getActivityTab().getWebContents());
276 272
277 mOfflinePageBridge.savePage(getActivity().getActivityTab().getWe bContents(), 273 mOfflinePageBridge.savePage(getActivity().getActivityTab().getWe bContents(),
278 BOOKMARK_ID, new SavePageCallback() { 274 BOOKMARK_ID, new SavePageCallback() {
279 @Override 275 @Override
280 public void onSavePageDone(int savePageResult, Strin g url) { 276 public void onSavePageDone(
277 int savePageResult, String url, long offline Id) {
281 assertEquals( 278 assertEquals(
282 "Requested and returned URLs differ.", e xpectedUrl, url); 279 "Requested and returned URLs differ.", e xpectedUrl, url);
283 assertEquals( 280 assertEquals(
284 "Save result incorrect.", expectedResult , savePageResult); 281 "Save result incorrect.", expectedResult , savePageResult);
285 semaphore.release(); 282 semaphore.release();
286 } 283 }
287 }); 284 });
288 } 285 }
289 }); 286 });
290 assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)); 287 assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 322
326 private void forceConnectivityStateOnUiThread(final boolean state) { 323 private void forceConnectivityStateOnUiThread(final boolean state) {
327 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 324 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
328 @Override 325 @Override
329 public void run() { 326 public void run() {
330 NetworkChangeNotifier.forceConnectivityState(state); 327 NetworkChangeNotifier.forceConnectivityState(state);
331 } 328 }
332 }); 329 });
333 } 330 }
334 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698