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