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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java

Issue 2076463002: [Custom Tabs] Implement "Read It Later" Behind a Flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 4 years, 6 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.customtabs; 5 package org.chromium.chrome.browser.customtabs;
6 6
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE; 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE;
8 8
9 import android.app.Activity; 9 import android.app.Activity;
10 import android.app.Application; 10 import android.app.Application;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 import android.widget.ImageButton; 42 import android.widget.ImageButton;
43 43
44 import org.chromium.base.PathUtils; 44 import org.chromium.base.PathUtils;
45 import org.chromium.base.ThreadUtils; 45 import org.chromium.base.ThreadUtils;
46 import org.chromium.base.library_loader.LibraryLoader; 46 import org.chromium.base.library_loader.LibraryLoader;
47 import org.chromium.base.library_loader.LibraryProcessType; 47 import org.chromium.base.library_loader.LibraryProcessType;
48 import org.chromium.base.test.util.CommandLineFlags; 48 import org.chromium.base.test.util.CommandLineFlags;
49 import org.chromium.base.test.util.Restriction; 49 import org.chromium.base.test.util.Restriction;
50 import org.chromium.chrome.R; 50 import org.chromium.chrome.R;
51 import org.chromium.chrome.browser.ChromeActivity; 51 import org.chromium.chrome.browser.ChromeActivity;
52 import org.chromium.chrome.browser.ChromeFeatureList;
52 import org.chromium.chrome.browser.ChromeSwitches; 53 import org.chromium.chrome.browser.ChromeSwitches;
53 import org.chromium.chrome.browser.ChromeTabbedActivity; 54 import org.chromium.chrome.browser.ChromeTabbedActivity;
54 import org.chromium.chrome.browser.IntentHandler; 55 import org.chromium.chrome.browser.IntentHandler;
55 import org.chromium.chrome.browser.TabsOpenedFromExternalAppTest; 56 import org.chromium.chrome.browser.TabsOpenedFromExternalAppTest;
56 import org.chromium.chrome.browser.appmenu.AppMenuHandler; 57 import org.chromium.chrome.browser.appmenu.AppMenuHandler;
57 import org.chromium.chrome.browser.document.ChromeLauncherActivity; 58 import org.chromium.chrome.browser.document.ChromeLauncherActivity;
58 import org.chromium.chrome.browser.prerender.ExternalPrerenderHandler; 59 import org.chromium.chrome.browser.prerender.ExternalPrerenderHandler;
59 import org.chromium.chrome.browser.profiles.Profile; 60 import org.chromium.chrome.browser.profiles.Profile;
60 import org.chromium.chrome.browser.tab.EmptyTabObserver; 61 import org.chromium.chrome.browser.tab.EmptyTabObserver;
61 import org.chromium.chrome.browser.tab.Tab; 62 import org.chromium.chrome.browser.tab.Tab;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 private static final String TEST_PAGE_COPY = "/chrome/test/data/android/ google.html"; 101 private static final String TEST_PAGE_COPY = "/chrome/test/data/android/ google.html";
101 102
102 @Override 103 @Override
103 public void onReceive(Context context, Intent intent) { 104 public void onReceive(Context context, Intent intent) {
104 // Note: even if this assertion fails, the test might still pass, be cause 105 // Note: even if this assertion fails, the test might still pass, be cause
105 // BroadcastReceiver is not treated as part of the instrumentation t est. 106 // BroadcastReceiver is not treated as part of the instrumentation t est.
106 assertEquals(mTestServer.getURL(TEST_PAGE_COPY), intent.getDataStrin g()); 107 assertEquals(mTestServer.getURL(TEST_PAGE_COPY), intent.getDataStrin g());
107 } 108 }
108 } 109 }
109 110
111 private static final String READ_IT_LATER_FEATURE = "ReadItLaterInMenu";
110 private static final int MAX_MENU_CUSTOM_ITEMS = 5; 112 private static final int MAX_MENU_CUSTOM_ITEMS = 5;
111 private static final int NUM_CHROME_MENU_ITEMS = 3; 113 private static final int NUM_CHROME_MENU_ITEMS = 3;
112 private static final String 114 private static final String
113 TEST_ACTION = "org.chromium.chrome.browser.customtabs.TEST_PENDING_I NTENT_SENT"; 115 TEST_ACTION = "org.chromium.chrome.browser.customtabs.TEST_PENDING_I NTENT_SENT";
114 private static final String TEST_PAGE = "/chrome/test/data/android/google.ht ml"; 116 private static final String TEST_PAGE = "/chrome/test/data/android/google.ht ml";
115 private static final String TEST_PAGE_2 = "/chrome/test/data/android/test.ht ml"; 117 private static final String TEST_PAGE_2 = "/chrome/test/data/android/test.ht ml";
116 private static final String GEOLOCATION_PAGE = 118 private static final String GEOLOCATION_PAGE =
117 "/chrome/test/data/geolocation/geolocation_on_load.html"; 119 "/chrome/test/data/geolocation/geolocation_on_load.html";
118 private static final String SELECT_POPUP_PAGE = "/chrome/test/data/android/s elect.html"; 120 private static final String SELECT_POPUP_PAGE = "/chrome/test/data/android/s elect.html";
119 private static final String FRAGMENT_TEST_PAGE = "/chrome/test/data/android/ fragment.html"; 121 private static final String FRAGMENT_TEST_PAGE = "/chrome/test/data/android/ fragment.html";
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 */ 341 */
340 @SmallTest 342 @SmallTest
341 public void testAppMenu() throws InterruptedException { 343 public void testAppMenu() throws InterruptedException {
342 Intent intent = createMinimalCustomTabIntent(); 344 Intent intent = createMinimalCustomTabIntent();
343 int numMenuEntries = 1; 345 int numMenuEntries = 1;
344 addMenuEntriesToIntent(intent, numMenuEntries); 346 addMenuEntriesToIntent(intent, numMenuEntries);
345 startCustomTabActivityWithIntent(intent); 347 startCustomTabActivityWithIntent(intent);
346 348
347 openAppMenuAndAssertMenuShown(); 349 openAppMenuAndAssertMenuShown();
348 Menu menu = getActivity().getAppMenuHandler().getAppMenu().getMenu(); 350 Menu menu = getActivity().getAppMenuHandler().getAppMenu().getMenu();
349 final int expectedMenuSize = numMenuEntries + NUM_CHROME_MENU_ITEMS; 351 final int expectedMenuSize = numMenuEntries + NUM_CHROME_MENU_ITEMS
352 + (ChromeFeatureList.isEnabled(READ_IT_LATER_FEATURE) ? 1 : 0);
350 final int actualMenuSize = getActualMenuSize(menu); 353 final int actualMenuSize = getActualMenuSize(menu);
351 354
352 assertNotNull("App menu is not initialized: ", menu); 355 assertNotNull("App menu is not initialized: ", menu);
353 assertEquals(expectedMenuSize, actualMenuSize); 356 assertEquals(expectedMenuSize, actualMenuSize);
354 assertNotNull(menu.findItem(R.id.forward_menu_id)); 357 assertNotNull(menu.findItem(R.id.forward_menu_id));
355 assertNotNull(menu.findItem(R.id.info_menu_id)); 358 assertNotNull(menu.findItem(R.id.info_menu_id));
356 assertNotNull(menu.findItem(R.id.reload_menu_id)); 359 assertNotNull(menu.findItem(R.id.reload_menu_id));
357 assertNotNull(menu.findItem(R.id.find_in_page_id)); 360 assertNotNull(menu.findItem(R.id.find_in_page_id));
358 assertNotNull(menu.findItem(R.id.open_in_browser_id)); 361 assertNotNull(menu.findItem(R.id.open_in_browser_id));
359 assertFalse(menu.findItem(R.id.share_row_menu_id).isVisible()); 362 assertFalse(menu.findItem(R.id.share_row_menu_id).isVisible());
(...skipping 22 matching lines...) Expand all
382 */ 385 */
383 @SmallTest 386 @SmallTest
384 public void testMaxMenuItems() throws InterruptedException { 387 public void testMaxMenuItems() throws InterruptedException {
385 Intent intent = createMinimalCustomTabIntent(); 388 Intent intent = createMinimalCustomTabIntent();
386 int numMenuEntries = 7; 389 int numMenuEntries = 7;
387 addMenuEntriesToIntent(intent, numMenuEntries); 390 addMenuEntriesToIntent(intent, numMenuEntries);
388 startCustomTabActivityWithIntent(intent); 391 startCustomTabActivityWithIntent(intent);
389 392
390 openAppMenuAndAssertMenuShown(); 393 openAppMenuAndAssertMenuShown();
391 Menu menu = getActivity().getAppMenuHandler().getAppMenu().getMenu(); 394 Menu menu = getActivity().getAppMenuHandler().getAppMenu().getMenu();
392 final int expectedMenuSize = MAX_MENU_CUSTOM_ITEMS + NUM_CHROME_MENU_ITE MS; 395 final int expectedMenuSize = MAX_MENU_CUSTOM_ITEMS + NUM_CHROME_MENU_ITE MS
396 + (ChromeFeatureList.isEnabled(READ_IT_LATER_FEATURE) ? 1 : 0);
393 final int actualMenuSize = getActualMenuSize(menu); 397 final int actualMenuSize = getActualMenuSize(menu);
394 assertNotNull("App menu is not initialized: ", menu); 398 assertNotNull("App menu is not initialized: ", menu);
395 assertEquals(expectedMenuSize, actualMenuSize); 399 assertEquals(expectedMenuSize, actualMenuSize);
396 } 400 }
397 401
398 /** 402 /**
399 * Test whether the custom menu is correctly shown and clicking it sends the right 403 * Test whether the custom menu is correctly shown and clicking it sends the right
400 * {@link PendingIntent}. 404 * {@link PendingIntent}.
401 */ 405 */
402 @SmallTest 406 @SmallTest
(...skipping 23 matching lines...) Expand all
426 } 430 }
427 }); 431 });
428 } 432 }
429 433
430 /** 434 /**
431 * Test whether clicking "Open in Chrome" takes us to a chrome normal tab, l oading the same url. 435 * Test whether clicking "Open in Chrome" takes us to a chrome normal tab, l oading the same url.
432 */ 436 */
433 @SmallTest 437 @SmallTest
434 public void testOpenInBrowser() throws InterruptedException { 438 public void testOpenInBrowser() throws InterruptedException {
435 startCustomTabActivityWithIntent(createMinimalCustomTabIntent()); 439 startCustomTabActivityWithIntent(createMinimalCustomTabIntent());
436 IntentFilter filter = new IntentFilter(Intent.ACTION_VIEW);
437 filter.addDataScheme(Uri.parse(mTestServer.getURL("/")).getScheme());
438 final ActivityMonitor monitor = getInstrumentation().addMonitor(filter, null, false);
439 openAppMenuAndAssertMenuShown(); 440 openAppMenuAndAssertMenuShown();
440 final String menuItemTitle = mActivity.getString(R.string.menu_open_in_p roduct_default); 441 if (ChromeFeatureList.isEnabled(READ_IT_LATER_FEATURE)) {
441 ThreadUtils.runOnUiThread(new Runnable() { 442 // TODO(ianwen): implement this test after read it later becomes a s ettled feature.
442 @Override 443 } else {
443 public void run() { 444 IntentFilter filter = new IntentFilter(Intent.ACTION_VIEW);
444 MenuItem item = mActivity.getAppMenuHandler() 445 filter.addDataScheme(Uri.parse(mTestServer.getURL("/")).getScheme()) ;
445 .getAppMenu().getMenu().findItem(R.id.open_in_browser_id ); 446 final ActivityMonitor monitor = getInstrumentation().addMonitor(filt er, null, false);
446 assertNotNull(item); 447 final String menuItemTitle = mActivity.getString(R.string.menu_open_ in_product_default);
447 assertEquals(menuItemTitle, item.getTitle().toString()); 448 ThreadUtils.runOnUiThread(new Runnable() {
448 mActivity.onMenuOrKeyboardAction(R.id.open_in_browser_id, false) ; 449 @Override
449 } 450 public void run() {
450 }); 451 MenuItem item = mActivity.getAppMenuHandler()
451 CriteriaHelper.pollInstrumentationThread(new Criteria() { 452 .getAppMenu().getMenu().findItem(R.id.open_in_browse r_id);
452 @Override 453 assertNotNull(item);
453 public boolean isSatisfied() { 454 assertEquals(menuItemTitle, item.getTitle().toString());
454 return getInstrumentation().checkMonitorHit(monitor, 1); 455 mActivity.onMenuOrKeyboardAction(R.id.open_in_browser_id, fa lse);
455 } 456 }
456 }); 457 });
458 CriteriaHelper.pollInstrumentationThread(new Criteria() {
459 @Override
460 public boolean isSatisfied() {
461 return getInstrumentation().checkMonitorHit(monitor, 1);
462 }
463 });
464 }
457 } 465 }
458 466
459 /** 467 /**
460 * Test whether a custom tab can be reparented to a new activity. 468 * Test whether a custom tab can be reparented to a new activity.
461 */ 469 */
462 @SmallTest 470 @SmallTest
463 public void testTabReparentingBasic() throws InterruptedException { 471 public void testTabReparentingBasic() throws InterruptedException {
464 startCustomTabActivityWithIntent(createMinimalCustomTabIntent()); 472 startCustomTabActivityWithIntent(createMinimalCustomTabIntent());
465 reparentAndVerifyTab(); 473 reparentAndVerifyTab();
466 } 474 }
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 TabObserver observer = new EmptyTabObserver() { 1288 TabObserver observer = new EmptyTabObserver() {
1281 @Override 1289 @Override
1282 public void onHidden(Tab tab) { 1290 public void onHidden(Tab tab) {
1283 tabHiddenHelper.notifyCalled(); 1291 tabHiddenHelper.notifyCalled();
1284 } 1292 }
1285 }; 1293 };
1286 tabToBeReparented.addObserver(observer); 1294 tabToBeReparented.addObserver(observer);
1287 ThreadUtils.postOnUiThread(new Runnable() { 1295 ThreadUtils.postOnUiThread(new Runnable() {
1288 @Override 1296 @Override
1289 public void run() { 1297 public void run() {
1290 mActivity.openCurrentUrlInBrowser(true); 1298 mActivity.openCurrentUrlInBrowser(true, true);
1291 assertNull(mActivity.getActivityTab()); 1299 assertNull(mActivity.getActivityTab());
1292 } 1300 }
1293 }); 1301 });
1294 // Use the extended CriteriaHelper timeout to make sure we get an activi ty 1302 // Use the extended CriteriaHelper timeout to make sure we get an activi ty
1295 final Activity lastActivity = 1303 final Activity lastActivity =
1296 monitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX_TI ME_TO_POLL); 1304 monitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX_TI ME_TO_POLL);
1297 assertNotNull("Monitor did not get an activity before hitting the timeou t", lastActivity); 1305 assertNotNull("Monitor did not get an activity before hitting the timeou t", lastActivity);
1298 assertTrue("Expected lastActivity to be a ChromeActivity, was " 1306 assertTrue("Expected lastActivity to be a ChromeActivity, was "
1299 + lastActivity.getClass().getName(), 1307 + lastActivity.getClass().getName(),
1300 lastActivity instanceof ChromeActivity); 1308 lastActivity instanceof ChromeActivity);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 if (jsonText.equalsIgnoreCase("null")) jsonText = ""; 1416 if (jsonText.equalsIgnoreCase("null")) jsonText = "";
1409 value = jsonText; 1417 value = jsonText;
1410 } catch (InterruptedException | TimeoutException e) { 1418 } catch (InterruptedException | TimeoutException e) {
1411 e.printStackTrace(); 1419 e.printStackTrace();
1412 return false; 1420 return false;
1413 } 1421 }
1414 return TextUtils.equals(mExpected, value); 1422 return TextUtils.equals(mExpected, value);
1415 } 1423 }
1416 } 1424 }
1417 } 1425 }
OLDNEW
« no previous file with comments | « chrome/android/java/strings/android_chrome_strings.grd ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698