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