OLD | NEW |
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; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.os.Environment; | 7 import android.os.Environment; |
8 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
9 import android.test.suitebuilder.annotation.Smoke; | 9 import android.test.suitebuilder.annotation.Smoke; |
10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
11 import android.util.Base64; | 11 import android.util.Base64; |
12 import android.view.KeyEvent; | 12 import android.view.KeyEvent; |
13 | 13 |
14 import org.chromium.base.ThreadUtils; | 14 import org.chromium.base.ThreadUtils; |
15 import org.chromium.base.test.util.DisableIf; | 15 import org.chromium.base.test.util.DisableIf; |
16 import org.chromium.base.test.util.DisabledTest; | 16 import org.chromium.base.test.util.DisabledTest; |
17 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
18 import org.chromium.base.test.util.Restriction; | 18 import org.chromium.base.test.util.Restriction; |
19 import org.chromium.base.test.util.UrlUtils; | 19 import org.chromium.base.test.util.UrlUtils; |
20 import org.chromium.chrome.R; | 20 import org.chromium.chrome.R; |
21 import org.chromium.chrome.browser.omnibox.LocationBarLayout; | 21 import org.chromium.chrome.browser.omnibox.LocationBarLayout; |
22 import org.chromium.chrome.browser.omnibox.UrlBar; | 22 import org.chromium.chrome.browser.omnibox.UrlBar; |
| 23 import org.chromium.chrome.browser.omnibox.UrlContainer; |
23 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 24 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
24 import org.chromium.chrome.browser.tab.Tab; | 25 import org.chromium.chrome.browser.tab.Tab; |
25 import org.chromium.chrome.browser.tab.TabObserver; | 26 import org.chromium.chrome.browser.tab.TabObserver; |
26 import org.chromium.chrome.browser.tabmodel.TabModel; | 27 import org.chromium.chrome.browser.tabmodel.TabModel; |
27 import org.chromium.chrome.browser.tabmodel.TabModelUtils; | 28 import org.chromium.chrome.browser.tabmodel.TabModelUtils; |
28 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; | 29 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; |
29 import org.chromium.chrome.test.util.ChromeRestriction; | 30 import org.chromium.chrome.test.util.ChromeRestriction; |
30 import org.chromium.chrome.test.util.ChromeTabUtils; | 31 import org.chromium.chrome.test.util.ChromeTabUtils; |
31 import org.chromium.chrome.test.util.OmniboxTestUtils; | 32 import org.chromium.chrome.test.util.OmniboxTestUtils; |
32 import org.chromium.chrome.test.util.browser.TabLoadObserver; | 33 import org.chromium.chrome.test.util.browser.TabLoadObserver; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 super.tearDown(); | 68 super.tearDown(); |
68 } | 69 } |
69 | 70 |
70 private void navigateAndObserve(final String startUrl, final String endUrl) | 71 private void navigateAndObserve(final String startUrl, final String endUrl) |
71 throws Exception { | 72 throws Exception { |
72 new TabLoadObserver(getActivity().getActivityTab()).fullyLoadUrl(startUr
l); | 73 new TabLoadObserver(getActivity().getActivityTab()).fullyLoadUrl(startUr
l); |
73 | 74 |
74 CriteriaHelper.pollUiThread(new Criteria() { | 75 CriteriaHelper.pollUiThread(new Criteria() { |
75 @Override | 76 @Override |
76 public boolean isSatisfied() { | 77 public boolean isSatisfied() { |
77 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.u
rl_bar); | 78 final UrlContainer urlContainer = |
78 assertNotNull("urlBar is null", urlBar); | 79 (UrlContainer) getActivity().findViewById(R.id.url_conta
iner); |
| 80 assertNotNull("URL Container is null", urlContainer); |
79 | 81 |
80 return TextUtils.equals(expectedLocation(endUrl), urlBar.getText
().toString()) | 82 return TextUtils.equals(expectedLocation(endUrl), urlContainer.g
etText()) |
81 && TextUtils.equals(endUrl, getActivity().getActivityTab
().getUrl()); | 83 && TextUtils.equals(endUrl, getActivity().getActivityTab
().getUrl()); |
82 } | 84 } |
83 }); | 85 }); |
84 } | 86 } |
85 | 87 |
86 /** | 88 /** |
87 * Types the passed text in the omnibox to trigger a navigation. You can pas
s a URL or a search | 89 * Types the passed text in the omnibox to trigger a navigation. You can pas
s a URL or a search |
88 * term. This code triggers suggestions and prerendering; unless you are tes
ting these | 90 * term. This code triggers suggestions and prerendering; unless you are tes
ting these |
89 * features specifically, you should use loadUrl() which is less prone to fl
akyness. | 91 * features specifically, you should use loadUrl() which is less prone to fl
akyness. |
90 * | 92 * |
(...skipping 17 matching lines...) Expand all Loading... |
108 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); | 110 (LocationBarLayout) getActivity().findViewById(R.id.location_bar
); |
109 OmniboxTestUtils.waitForOmniboxSuggestions(locationBar); | 111 OmniboxTestUtils.waitForOmniboxSuggestions(locationBar); |
110 | 112 |
111 // Loads the url. | 113 // Loads the url. |
112 TabLoadObserver observer = | 114 TabLoadObserver observer = |
113 new TabLoadObserver(getActivity().getActivityTab(), expectedTitl
e, null); | 115 new TabLoadObserver(getActivity().getActivityTab(), expectedTitl
e, null); |
114 KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEvent.KEYCO
DE_ENTER); | 116 KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEvent.KEYCO
DE_ENTER); |
115 observer.assertLoaded(); | 117 observer.assertLoaded(); |
116 | 118 |
117 // The URL has been set before the page notification was broadcast, so i
t is safe to access. | 119 // The URL has been set before the page notification was broadcast, so i
t is safe to access. |
118 return urlBar.getText().toString(); | 120 final UrlContainer urlContainer = |
| 121 (UrlContainer) getActivity().findViewById(R.id.url_container); |
| 122 return urlContainer.getText(); |
119 } | 123 } |
120 | 124 |
121 /** | 125 /** |
122 * @return the expected contents of the location bar after navigating to url
. | 126 * @return the expected contents of the location bar after navigating to url
. |
123 */ | 127 */ |
124 private String expectedLocation(String url) { | 128 private String expectedLocation(String url) { |
125 assertTrue(url.startsWith(HTTP_SCHEME)); | 129 assertTrue(url.startsWith(HTTP_SCHEME)); |
126 return url.replaceFirst(HTTP_SCHEME, ""); | 130 return url.replaceFirst(HTTP_SCHEME, ""); |
127 } | 131 } |
128 | 132 |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 assert false : "Unexpected Exception"; | 453 assert false : "Unexpected Exception"; |
450 } | 454 } |
451 return null; | 455 return null; |
452 } | 456 } |
453 | 457 |
454 @Override | 458 @Override |
455 public void startMainActivity() throws InterruptedException { | 459 public void startMainActivity() throws InterruptedException { |
456 startMainActivityFromLauncher(); | 460 startMainActivityFromLauncher(); |
457 } | 461 } |
458 } | 462 } |
OLD | NEW |