| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/chromeos/cros/cros_library.h" | 6 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 6 #include "chrome/browser/chromeos/login/merge_session_load_page.h" | 7 #include "chrome/browser/chromeos/login/merge_session_load_page.h" |
| 7 #include "chrome/browser/chromeos/login/user_manager.h" | 8 #include "chrome/browser/chromeos/login/user_manager.h" |
| 8 #include "chrome/browser/chromeos/settings/cros_settings.h" | 9 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 9 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 10 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 11 #include "content/public/browser/interstitial_page.h" | 12 #include "content/public/browser/interstitial_page.h" |
| 12 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
| 13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/test/test_browser_thread.h" | |
| 15 #include "content/public/test/web_contents_tester.h" | 15 #include "content/public/test/web_contents_tester.h" |
| 16 | 16 |
| 17 using content::BrowserThread; | |
| 18 using content::InterstitialPage; | 17 using content::InterstitialPage; |
| 19 using content::WebContents; | 18 using content::WebContents; |
| 20 using content::WebContentsTester; | 19 using content::WebContentsTester; |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 const char kURL1[] = "http://www.google.com/"; | 23 const char kURL1[] = "http://www.google.com/"; |
| 25 const char kURL2[] = "http://mail.google.com/"; | 24 const char kURL2[] = "http://mail.google.com/"; |
| 26 | 25 |
| 27 } // namespace | 26 } // namespace |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 interstitial_page_->DontCreateViewForTesting(); | 40 interstitial_page_->DontCreateViewForTesting(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 MergeSessionLoadPageTest* test_page_; | 44 MergeSessionLoadPageTest* test_page_; |
| 46 | 45 |
| 47 DISALLOW_COPY_AND_ASSIGN(TestMergeSessionLoadPage); | 46 DISALLOW_COPY_AND_ASSIGN(TestMergeSessionLoadPage); |
| 48 }; | 47 }; |
| 49 | 48 |
| 50 class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness { | 49 class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness { |
| 51 public: | 50 protected: |
| 52 MergeSessionLoadPageTest() | 51 virtual void SetUp() OVERRIDE { |
| 53 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), | 52 ChromeRenderViewHostTestHarness::SetUp(); |
| 54 file_user_blocking_thread_( | 53 #if defined OS_CHROMEOS |
| 55 BrowserThread::FILE_USER_BLOCKING, base::MessageLoop::current()), | 54 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
| 56 io_thread_(BrowserThread::IO, base::MessageLoop::current()) { | 55 #endif |
| 56 } |
| 57 |
| 58 virtual void TearDown() OVERRIDE { |
| 59 #if defined OS_CHROMEOS |
| 60 // Clean up pending tasks that might depend on the user manager. |
| 61 base::RunLoop().RunUntilIdle(); |
| 62 test_user_manager_.reset(); |
| 63 #endif |
| 64 ChromeRenderViewHostTestHarness::TearDown(); |
| 57 } | 65 } |
| 58 | 66 |
| 59 void Navigate(const char* url, int page_id) { | 67 void Navigate(const char* url, int page_id) { |
| 60 WebContentsTester::For(web_contents())->TestDidNavigate( | 68 WebContentsTester::For(web_contents())->TestDidNavigate( |
| 61 web_contents()->GetRenderViewHost(), page_id, GURL(url), | 69 web_contents()->GetRenderViewHost(), page_id, GURL(url), |
| 62 content::PAGE_TRANSITION_TYPED); | 70 content::PAGE_TRANSITION_TYPED); |
| 63 } | 71 } |
| 64 | 72 |
| 65 void ShowInterstitial(const char* url) { | 73 void ShowInterstitial(const char* url) { |
| 66 (new TestMergeSessionLoadPage(web_contents(), GURL(url), this))->Show(); | 74 (new TestMergeSessionLoadPage(web_contents(), GURL(url), this))->Show(); |
| 67 } | 75 } |
| 68 | 76 |
| 69 // Returns the MergeSessionLoadPage currently showing or NULL if none is | 77 // Returns the MergeSessionLoadPage currently showing or NULL if none is |
| 70 // showing. | 78 // showing. |
| 71 InterstitialPage* GetMergeSessionLoadPage() { | 79 InterstitialPage* GetMergeSessionLoadPage() { |
| 72 return InterstitialPage::GetInterstitialPage(web_contents()); | 80 return InterstitialPage::GetInterstitialPage(web_contents()); |
| 73 } | 81 } |
| 74 | 82 |
| 75 private: | 83 private: |
| 76 content::TestBrowserThread ui_thread_; | |
| 77 content::TestBrowserThread file_user_blocking_thread_; | |
| 78 content::TestBrowserThread io_thread_; | |
| 79 | |
| 80 ScopedStubCrosEnabler stub_cros_enabler_; | 84 ScopedStubCrosEnabler stub_cros_enabler_; |
| 81 ScopedTestDeviceSettingsService test_device_settings_service_; | 85 ScopedTestDeviceSettingsService test_device_settings_service_; |
| 82 ScopedTestCrosSettings test_cros_settings_; | 86 ScopedTestCrosSettings test_cros_settings_; |
| 83 ScopedTestUserManager test_user_manager_; | 87 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(MergeSessionLoadPageTest); | |
| 86 }; | 88 }; |
| 87 | 89 |
| 88 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { | 90 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { |
| 89 UserManager::Get()->SetMergeSessionState( | 91 UserManager::Get()->SetMergeSessionState( |
| 90 UserManager::MERGE_STATUS_DONE); | 92 UserManager::MERGE_STATUS_DONE); |
| 91 // Start a load. | 93 // Start a load. |
| 92 Navigate(kURL1, 1); | 94 Navigate(kURL1, 1); |
| 93 // Load next page. | 95 // Load next page. |
| 94 controller().LoadURL(GURL(kURL2), content::Referrer(), | 96 controller().LoadURL(GURL(kURL2), content::Referrer(), |
| 95 content::PAGE_TRANSITION_TYPED, std::string()); | 97 content::PAGE_TRANSITION_TYPED, std::string()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 107 Navigate(kURL1, 1); | 109 Navigate(kURL1, 1); |
| 108 // Load next page. | 110 // Load next page. |
| 109 controller().LoadURL(GURL(kURL2), content::Referrer(), | 111 controller().LoadURL(GURL(kURL2), content::Referrer(), |
| 110 content::PAGE_TRANSITION_TYPED, std::string()); | 112 content::PAGE_TRANSITION_TYPED, std::string()); |
| 111 | 113 |
| 112 // Simulate the load causing an merge session interstitial page | 114 // Simulate the load causing an merge session interstitial page |
| 113 // to be shown. | 115 // to be shown. |
| 114 ShowInterstitial(kURL2); | 116 ShowInterstitial(kURL2); |
| 115 InterstitialPage* interstitial = GetMergeSessionLoadPage(); | 117 InterstitialPage* interstitial = GetMergeSessionLoadPage(); |
| 116 ASSERT_TRUE(interstitial); | 118 ASSERT_TRUE(interstitial); |
| 117 base::MessageLoop::current()->RunUntilIdle(); | 119 base::RunLoop().RunUntilIdle(); |
| 118 | 120 |
| 119 // Simulate merge session completion. | 121 // Simulate merge session completion. |
| 120 UserManager::Get()->SetMergeSessionState( | 122 UserManager::Get()->SetMergeSessionState( |
| 121 UserManager::MERGE_STATUS_DONE); | 123 UserManager::MERGE_STATUS_DONE); |
| 122 base::MessageLoop::current()->RunUntilIdle(); | 124 base::RunLoop().RunUntilIdle(); |
| 123 | 125 |
| 124 // The URL remains to be URL2. | 126 // The URL remains to be URL2. |
| 125 EXPECT_EQ(kURL2, web_contents()->GetURL().spec()); | 127 EXPECT_EQ(kURL2, web_contents()->GetURL().spec()); |
| 126 | 128 |
| 127 // Commit navigation and the interstitial page is gone. | 129 // Commit navigation and the interstitial page is gone. |
| 128 Navigate(kURL2, 2); | 130 Navigate(kURL2, 2); |
| 129 EXPECT_FALSE(GetMergeSessionLoadPage()); | 131 EXPECT_FALSE(GetMergeSessionLoadPage()); |
| 130 } | 132 } |
| 131 | 133 |
| 132 } // namespace chromeos | 134 } // namespace chromeos |
| OLD | NEW |