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 namespace { |
| 20 |
| 21 const char kURL1[] = "http://www.google.com/"; |
| 22 const char kURL2[] = "http://mail.google.com/"; |
| 23 |
| 24 } // namespace |
| 25 |
| 26 namespace chromeos { |
| 27 |
| 28 class MergeSessionLoadPageTest; |
| 29 |
| 30 // An MergeSessionLoadPage class that does not create windows. |
| 31 class TestMergeSessionLoadPage : public MergeSessionLoadPage { |
| 32 public: |
| 33 TestMergeSessionLoadPage(WebContents* web_contents, |
| 34 const GURL& url, |
| 35 MergeSessionLoadPageTest* test_page) |
| 36 : MergeSessionLoadPage(web_contents, url, CompletionCallback()), |
| 37 test_page_(test_page) { |
| 38 interstitial_page_->DontCreateViewForTesting(); |
| 39 } |
| 40 |
| 41 private: |
| 42 MergeSessionLoadPageTest* test_page_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(TestMergeSessionLoadPage); |
| 45 }; |
| 46 |
| 47 class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness { |
| 48 public: |
| 49 MergeSessionLoadPageTest() |
| 50 : ui_thread_(BrowserThread::UI, MessageLoop::current()), |
| 51 file_user_blocking_thread_( |
| 52 BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()), |
| 53 io_thread_(BrowserThread::IO, MessageLoop::current()) { |
| 54 } |
| 55 |
| 56 void Navigate(const char* url, int page_id) { |
| 57 WebContentsTester::For(web_contents())->TestDidNavigate( |
| 58 web_contents()->GetRenderViewHost(), page_id, GURL(url), |
| 59 content::PAGE_TRANSITION_TYPED); |
| 60 } |
| 61 |
| 62 void ShowInterstitial(const char* url) { |
| 63 (new TestMergeSessionLoadPage(web_contents(), GURL(url), this))->Show(); |
| 64 } |
| 65 |
| 66 // Returns the MergeSessionLoadPage currently showing or NULL if none is |
| 67 // showing. |
| 68 InterstitialPage* GetMergeSessionLoadPage() { |
| 69 return InterstitialPage::GetInterstitialPage(web_contents()); |
| 70 } |
| 71 |
| 72 private: |
| 73 content::TestBrowserThread ui_thread_; |
| 74 content::TestBrowserThread file_user_blocking_thread_; |
| 75 content::TestBrowserThread io_thread_; |
| 76 |
| 77 // Initializes / shuts down a stub CrosLibrary. |
| 78 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(MergeSessionLoadPageTest); |
| 81 }; |
| 82 |
| 83 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { |
| 84 UserManager::Get()->SetMergeSessionState( |
| 85 UserManager::MERGE_STATUS_DONE); |
| 86 // Start a load. |
| 87 Navigate(kURL1, 1); |
| 88 // Load next page. |
| 89 controller().LoadURL(GURL(kURL2), content::Referrer(), |
| 90 content::PAGE_TRANSITION_TYPED, std::string()); |
| 91 |
| 92 // Simulate the load causing an merge session interstitial page |
| 93 // to be shown. |
| 94 InterstitialPage* interstitial = GetMergeSessionLoadPage(); |
| 95 EXPECT_FALSE(interstitial); |
| 96 } |
| 97 |
| 98 TEST_F(MergeSessionLoadPageTest, MergeSessionPageShown) { |
| 99 UserManager::Get()->SetMergeSessionState( |
| 100 UserManager::MERGE_STATUS_IN_PROCESS); |
| 101 // Start a load. |
| 102 Navigate(kURL1, 1); |
| 103 // Load next page. |
| 104 controller().LoadURL(GURL(kURL2), content::Referrer(), |
| 105 content::PAGE_TRANSITION_TYPED, std::string()); |
| 106 |
| 107 // Simulate the load causing an merge session interstitial page |
| 108 // to be shown. |
| 109 ShowInterstitial(kURL2); |
| 110 InterstitialPage* interstitial = GetMergeSessionLoadPage(); |
| 111 ASSERT_TRUE(interstitial); |
| 112 MessageLoop::current()->RunUntilIdle(); |
| 113 |
| 114 // Simulate merge session completion. |
| 115 UserManager::Get()->SetMergeSessionState( |
| 116 UserManager::MERGE_STATUS_DONE); |
| 117 MessageLoop::current()->RunUntilIdle(); |
| 118 |
| 119 // The URL remains to be URL2. |
| 120 EXPECT_EQ(kURL2, web_contents()->GetURL().spec()); |
| 121 |
| 122 // Commit navigation and the interstitial page is gone. |
| 123 Navigate(kURL2, 2); |
| 124 EXPECT_FALSE(GetMergeSessionLoadPage()); |
| 125 } |
| 126 |
| 127 } // namespace chromeos |
OLD | NEW |