OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/run_loop.h" | 5 #include "base/run_loop.h" |
6 #include "base/time/time.h" | 6 #include "base/time/time.h" |
7 #include "chrome/browser/chromeos/login/signin/merge_session_load_page.h" | 7 #include "chrome/browser/chromeos/login/signin/merge_session_load_page.h" |
8 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" | 8 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" |
9 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" | 9 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" |
10 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | 10 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
11 #include "chrome/browser/chromeos/settings/cros_settings.h" | 11 #include "chrome/browser/chromeos/settings/cros_settings.h" |
12 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 12 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
14 #include "content/public/browser/interstitial_page.h" | 14 #include "content/public/browser/interstitial_page.h" |
15 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/navigation_entry.h" | |
17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
18 #include "content/public/test/web_contents_tester.h" | 17 #include "content/public/test/web_contents_tester.h" |
19 | 18 |
20 using content::InterstitialPage; | 19 using content::InterstitialPage; |
21 using content::WebContents; | 20 using content::WebContents; |
22 using content::WebContentsTester; | 21 using content::WebContentsTester; |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 const char kURL1[] = "http://www.google.com/"; | 25 const char kURL1[] = "http://www.google.com/"; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 57 |
59 void TearDown() override { | 58 void TearDown() override { |
60 #if defined OS_CHROMEOS | 59 #if defined OS_CHROMEOS |
61 // Clean up pending tasks that might depend on the user manager. | 60 // Clean up pending tasks that might depend on the user manager. |
62 base::RunLoop().RunUntilIdle(); | 61 base::RunLoop().RunUntilIdle(); |
63 test_user_manager_.reset(); | 62 test_user_manager_.reset(); |
64 #endif | 63 #endif |
65 ChromeRenderViewHostTestHarness::TearDown(); | 64 ChromeRenderViewHostTestHarness::TearDown(); |
66 } | 65 } |
67 | 66 |
68 void Navigate(const char* url, | 67 void Navigate(const char* url, int page_id) { |
69 int page_id, | 68 WebContentsTester::For(web_contents())->TestDidNavigate( |
70 int nav_entry_id, | 69 web_contents()->GetMainFrame(), page_id, GURL(url), |
71 bool did_create_new_entry) { | 70 ui::PAGE_TRANSITION_TYPED); |
72 WebContentsTester::For(web_contents()) | |
73 ->TestDidNavigate(web_contents()->GetMainFrame(), page_id, nav_entry_id, | |
74 did_create_new_entry, GURL(url), | |
75 ui::PAGE_TRANSITION_TYPED); | |
76 } | 71 } |
77 | 72 |
78 void ShowInterstitial(const char* url) { | 73 void ShowInterstitial(const char* url) { |
79 (new TestMergeSessionLoadPage(web_contents(), GURL(url)))->Show(); | 74 (new TestMergeSessionLoadPage(web_contents(), GURL(url)))->Show(); |
80 } | 75 } |
81 | 76 |
82 // Returns the MergeSessionLoadPage currently showing or NULL if none is | 77 // Returns the MergeSessionLoadPage currently showing or NULL if none is |
83 // showing. | 78 // showing. |
84 InterstitialPage* GetMergeSessionLoadPage() { | 79 InterstitialPage* GetMergeSessionLoadPage() { |
85 return InterstitialPage::GetInterstitialPage(web_contents()); | 80 return InterstitialPage::GetInterstitialPage(web_contents()); |
(...skipping 29 matching lines...) Expand all Loading... |
115 | 110 |
116 private: | 111 private: |
117 ScopedTestDeviceSettingsService test_device_settings_service_; | 112 ScopedTestDeviceSettingsService test_device_settings_service_; |
118 ScopedTestCrosSettings test_cros_settings_; | 113 ScopedTestCrosSettings test_cros_settings_; |
119 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 114 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
120 }; | 115 }; |
121 | 116 |
122 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { | 117 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { |
123 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE); | 118 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE); |
124 // Start a load. | 119 // Start a load. |
125 Navigate(kURL1, 1, 0, true); | 120 Navigate(kURL1, 1); |
126 // Load next page. | 121 // Load next page. |
127 controller().LoadURL(GURL(kURL2), content::Referrer(), | 122 controller().LoadURL(GURL(kURL2), content::Referrer(), |
128 ui::PAGE_TRANSITION_TYPED, std::string()); | 123 ui::PAGE_TRANSITION_TYPED, std::string()); |
129 | 124 |
130 // Simulate the load causing an merge session interstitial page | 125 // Simulate the load causing an merge session interstitial page |
131 // to be shown. | 126 // to be shown. |
132 InterstitialPage* interstitial = GetMergeSessionLoadPage(); | 127 InterstitialPage* interstitial = GetMergeSessionLoadPage(); |
133 EXPECT_FALSE(interstitial); | 128 EXPECT_FALSE(interstitial); |
134 } | 129 } |
135 | 130 |
136 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShownOnTimeout) { | 131 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShownOnTimeout) { |
137 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS); | 132 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS); |
138 SetSessionRestoreStart( | 133 SetSessionRestoreStart( |
139 base::Time::Now() + | 134 base::Time::Now() + |
140 base::TimeDelta::FromSeconds(kSessionMergeTimeout + 1)); | 135 base::TimeDelta::FromSeconds(kSessionMergeTimeout + 1)); |
141 | 136 |
142 // Start a load. | 137 // Start a load. |
143 Navigate(kURL1, 1, 0, true); | 138 Navigate(kURL1, 1); |
144 // Load next page. | 139 // Load next page. |
145 controller().LoadURL(GURL(kURL2), content::Referrer(), | 140 controller().LoadURL(GURL(kURL2), content::Referrer(), |
146 ui::PAGE_TRANSITION_TYPED, std::string()); | 141 ui::PAGE_TRANSITION_TYPED, std::string()); |
147 | 142 |
148 // Simulate the load causing an merge session interstitial page | 143 // Simulate the load causing an merge session interstitial page |
149 // to be shown. | 144 // to be shown. |
150 InterstitialPage* interstitial = GetMergeSessionLoadPage(); | 145 InterstitialPage* interstitial = GetMergeSessionLoadPage(); |
151 EXPECT_FALSE(interstitial); | 146 EXPECT_FALSE(interstitial); |
152 } | 147 } |
153 | 148 |
154 TEST_F(MergeSessionLoadPageTest, MergeSessionPageShown) { | 149 TEST_F(MergeSessionLoadPageTest, MergeSessionPageShown) { |
155 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS); | 150 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS); |
156 | 151 |
157 // Start a load. | 152 // Start a load. |
158 Navigate(kURL1, 1, 0, true); | 153 Navigate(kURL1, 1); |
159 // Load next page. | 154 // Load next page. |
160 controller().LoadURL(GURL(kURL2), content::Referrer(), | 155 controller().LoadURL(GURL(kURL2), content::Referrer(), |
161 ui::PAGE_TRANSITION_TYPED, std::string()); | 156 ui::PAGE_TRANSITION_TYPED, std::string()); |
162 int pending_id = controller().GetPendingEntry()->GetUniqueID(); | |
163 | 157 |
164 // Simulate the load causing an merge session interstitial page | 158 // Simulate the load causing an merge session interstitial page |
165 // to be shown. | 159 // to be shown. |
166 ShowInterstitial(kURL2); | 160 ShowInterstitial(kURL2); |
167 InterstitialPage* interstitial = GetMergeSessionLoadPage(); | 161 InterstitialPage* interstitial = GetMergeSessionLoadPage(); |
168 ASSERT_TRUE(interstitial); | 162 ASSERT_TRUE(interstitial); |
169 base::RunLoop().RunUntilIdle(); | 163 base::RunLoop().RunUntilIdle(); |
170 | 164 |
171 // Simulate merge session completion. | 165 // Simulate merge session completion. |
172 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE); | 166 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE); |
173 base::RunLoop().RunUntilIdle(); | 167 base::RunLoop().RunUntilIdle(); |
174 | 168 |
175 // The URL remains to be URL2. | 169 // The URL remains to be URL2. |
176 EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec()); | 170 EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec()); |
177 | 171 |
178 // Commit navigation and the interstitial page is gone. | 172 // Commit navigation and the interstitial page is gone. |
179 Navigate(kURL2, 2, pending_id, true); | 173 Navigate(kURL2, 2); |
180 EXPECT_FALSE(GetMergeSessionLoadPage()); | 174 EXPECT_FALSE(GetMergeSessionLoadPage()); |
181 } | 175 } |
182 | 176 |
183 } // namespace chromeos | 177 } // namespace chromeos |
OLD | NEW |