Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 6 #include "chrome/browser/chromeos/login/merge_session_load_page.h" | |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 8 #include "content/public/browser/interstitial_page.h" | |
| 9 #include "content/public/browser/navigation_controller.h" | |
| 10 #include "content/public/browser/web_contents.h" | |
| 11 #include "content/public/test/test_browser_thread.h" | |
| 12 #include "content/public/test/web_contents_tester.h" | |
| 13 | |
| 14 using content::BrowserThread; | |
| 15 using content::InterstitialPage; | |
| 16 using content::WebContents; | |
| 17 using content::WebContentsTester; | |
| 18 | |
| 19 static const char* kURL1 = "http://www.google.com/"; | |
| 20 static const char* kURL2 = "http://mail.google.com/"; | |
|
oshima
2013/02/15 22:40:52
put this in anonymous namespace. you can remove st
zel
2013/02/15 23:16:58
Done.
xiyuan
2013/02/15 23:43:07
nit: const char* kURL1 -> const char kURL1[]
zel
2013/02/15 23:51:05
Done.
| |
| 21 | |
| 22 namespace chromeos { | |
| 23 | |
| 24 class MergeSessionLoadPageTest; | |
| 25 | |
| 26 // An MergeSessionLoadPage class that does not create windows. | |
| 27 class TestMergeSessionLoadPage : public chromeos::MergeSessionLoadPage { | |
|
oshima
2013/02/15 22:40:52
you don't need chromeos:: namespace as you're alre
zel
2013/02/15 23:16:58
Done.
| |
| 28 public: | |
| 29 TestMergeSessionLoadPage(WebContents* web_contents, | |
| 30 const GURL& url, | |
| 31 MergeSessionLoadPageTest* test_page) | |
| 32 : chromeos::MergeSessionLoadPage(web_contents, url, CompletionCallback()), | |
| 33 test_page_(test_page) { | |
| 34 interstitial_page_->DontCreateViewForTesting(); | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 MergeSessionLoadPageTest* test_page_; | |
| 39 | |
| 40 DISALLOW_COPY_AND_ASSIGN(TestMergeSessionLoadPage); | |
| 41 }; | |
| 42 | |
| 43 class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness { | |
| 44 public: | |
| 45 MergeSessionLoadPageTest() | |
| 46 : ui_thread_(BrowserThread::UI, MessageLoop::current()), | |
| 47 file_user_blocking_thread_( | |
| 48 BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()), | |
| 49 io_thread_(BrowserThread::IO, MessageLoop::current()) { | |
| 50 } | |
| 51 | |
| 52 // ChromeRenderViewHostTestHarness overrides. | |
| 53 virtual void SetUp() OVERRIDE { | |
| 54 ChromeRenderViewHostTestHarness::SetUp(); | |
|
oshima
2013/02/15 22:40:52
don't you have to call ChromeRenderViewHostTestHar
zel
2013/02/15 23:16:58
Actually, I don't need to override either of these
| |
| 55 } | |
| 56 | |
| 57 void Navigate(const char* url, int page_id) { | |
| 58 WebContentsTester::For(web_contents())->TestDidNavigate( | |
| 59 web_contents()->GetRenderViewHost(), page_id, GURL(url), | |
| 60 content::PAGE_TRANSITION_TYPED); | |
| 61 } | |
| 62 | |
| 63 void ShowInterstitial(const char* url) { | |
| 64 (new TestMergeSessionLoadPage(web_contents(), GURL(url), this))->Show(); | |
| 65 } | |
| 66 | |
| 67 // Returns the MergeSessionLoadPage currently showing or NULL if none is | |
| 68 // showing. | |
| 69 InterstitialPage* GetMergeSessionLoadPage() { | |
| 70 return InterstitialPage::GetInterstitialPage(web_contents()); | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 content::TestBrowserThread ui_thread_; | |
| 75 content::TestBrowserThread file_user_blocking_thread_; | |
| 76 content::TestBrowserThread io_thread_; | |
| 77 | |
| 78 // Initializes / shuts down a stub CrosLibrary. | |
| 79 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(MergeSessionLoadPageTest); | |
| 82 }; | |
| 83 | |
| 84 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { | |
| 85 UserManager::Get()->SetMergeSessionState( | |
| 86 UserManager::MERGE_STATUS_DONE); | |
| 87 // Start a load. | |
| 88 Navigate(kURL1, 1); | |
| 89 // Load next page. | |
| 90 controller().LoadURL(GURL(kURL2), content::Referrer(), | |
| 91 content::PAGE_TRANSITION_TYPED, std::string()); | |
| 92 | |
| 93 // Simulate the load causing an merge session interstitial page | |
| 94 // to be shown. | |
| 95 InterstitialPage* interstitial = GetMergeSessionLoadPage(); | |
| 96 EXPECT_FALSE(interstitial); | |
| 97 } | |
| 98 | |
| 99 TEST_F(MergeSessionLoadPageTest, MergeSessionPageShown) { | |
| 100 UserManager::Get()->SetMergeSessionState( | |
| 101 UserManager::MERGE_STATUS_IN_PROCESS); | |
| 102 // Start a load. | |
| 103 Navigate(kURL1, 1); | |
| 104 // Load next page. | |
| 105 controller().LoadURL(GURL(kURL2), content::Referrer(), | |
| 106 content::PAGE_TRANSITION_TYPED, std::string()); | |
| 107 | |
| 108 // Simulate the load causing an merge session interstitial page | |
| 109 // to be shown. | |
| 110 ShowInterstitial(kURL2); | |
| 111 InterstitialPage* interstitial = GetMergeSessionLoadPage(); | |
| 112 ASSERT_TRUE(interstitial); | |
| 113 MessageLoop::current()->RunUntilIdle(); | |
| 114 | |
| 115 // Simulate merge session completion. | |
| 116 UserManager::Get()->SetMergeSessionState( | |
| 117 UserManager::MERGE_STATUS_DONE); | |
| 118 MessageLoop::current()->RunUntilIdle(); | |
| 119 | |
| 120 // The URL remains to be URL2. | |
| 121 EXPECT_EQ(kURL2, web_contents()->GetURL().spec()); | |
| 122 | |
| 123 // Commit navigation and the interstitial page is gone. | |
| 124 Navigate(kURL2, 2); | |
| 125 EXPECT_FALSE(GetMergeSessionLoadPage()); | |
| 126 } | |
| 127 | |
| 128 } // namespace chromeos | |
| OLD | NEW |