| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/cros/cros_library.h" | 5 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 6 #include "chrome/browser/chromeos/offline/offline_load_page.h" | 6 #include "chrome/browser/chromeos/offline/offline_load_page.h" |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 8 #include "content/public/browser/interstitial_page.h" | 8 #include "content/public/browser/interstitial_page.h" |
| 9 #include "content/public/browser/navigation_controller.h" | 9 #include "content/public/browser/navigation_controller.h" |
| 10 #include "content/public/browser/web_contents.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" | 11 #include "content/public/test/web_contents_tester.h" |
| 13 | 12 |
| 14 using content::BrowserThread; | |
| 15 using content::InterstitialPage; | 13 using content::InterstitialPage; |
| 16 using content::WebContents; | 14 using content::WebContents; |
| 17 using content::WebContentsTester; | 15 using content::WebContentsTester; |
| 18 | 16 |
| 19 static const char* kURL1 = "http://www.google.com/"; | 17 static const char* kURL1 = "http://www.google.com/"; |
| 20 static const char* kURL2 = "http://www.gmail.com/"; | 18 static const char* kURL2 = "http://www.gmail.com/"; |
| 21 | 19 |
| 22 namespace chromeos { | 20 namespace chromeos { |
| 23 | 21 |
| 24 class OfflineLoadPageTest; | 22 class OfflineLoadPageTest; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 45 | 43 |
| 46 class OfflineLoadPageTest : public ChromeRenderViewHostTestHarness { | 44 class OfflineLoadPageTest : public ChromeRenderViewHostTestHarness { |
| 47 public: | 45 public: |
| 48 // The decision the user made. | 46 // The decision the user made. |
| 49 enum UserResponse { | 47 enum UserResponse { |
| 50 PENDING, | 48 PENDING, |
| 51 OK, | 49 OK, |
| 52 CANCEL | 50 CANCEL |
| 53 }; | 51 }; |
| 54 | 52 |
| 55 OfflineLoadPageTest() | |
| 56 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), | |
| 57 file_user_blocking_thread_( | |
| 58 BrowserThread::FILE_USER_BLOCKING, base::MessageLoop::current()), | |
| 59 io_thread_(BrowserThread::IO, base::MessageLoop::current()) { | |
| 60 } | |
| 61 | |
| 62 virtual void SetUp() { | 53 virtual void SetUp() { |
| 63 ChromeRenderViewHostTestHarness::SetUp(); | 54 ChromeRenderViewHostTestHarness::SetUp(); |
| 64 user_response_ = PENDING; | 55 user_response_ = PENDING; |
| 65 } | 56 } |
| 66 | 57 |
| 67 void OnBlockingPageComplete(bool proceed) { | 58 void OnBlockingPageComplete(bool proceed) { |
| 68 if (proceed) | 59 if (proceed) |
| 69 user_response_ = OK; | 60 user_response_ = OK; |
| 70 else | 61 else |
| 71 user_response_ = CANCEL; | 62 user_response_ = CANCEL; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 83 | 74 |
| 84 // Returns the OfflineLoadPage currently showing or NULL if none is | 75 // Returns the OfflineLoadPage currently showing or NULL if none is |
| 85 // showing. | 76 // showing. |
| 86 InterstitialPage* GetOfflineLoadPage() { | 77 InterstitialPage* GetOfflineLoadPage() { |
| 87 return InterstitialPage::GetInterstitialPage(web_contents()); | 78 return InterstitialPage::GetInterstitialPage(web_contents()); |
| 88 } | 79 } |
| 89 | 80 |
| 90 UserResponse user_response() const { return user_response_; } | 81 UserResponse user_response() const { return user_response_; } |
| 91 | 82 |
| 92 private: | 83 private: |
| 84 friend class TestOfflineLoadPage; |
| 85 |
| 93 UserResponse user_response_; | 86 UserResponse user_response_; |
| 94 content::TestBrowserThread ui_thread_; | |
| 95 content::TestBrowserThread file_user_blocking_thread_; | |
| 96 content::TestBrowserThread io_thread_; | |
| 97 | 87 |
| 98 // Initializes / shuts down a stub CrosLibrary. | 88 // Initializes / shuts down a stub CrosLibrary. |
| 99 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; | 89 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(OfflineLoadPageTest); | |
| 102 }; | 90 }; |
| 103 | 91 |
| 104 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { | 92 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { |
| 105 test_page_->OnBlockingPageComplete(proceed); | 93 test_page_->OnBlockingPageComplete(proceed); |
| 106 } | 94 } |
| 107 | 95 |
| 108 TEST_F(OfflineLoadPageTest, OfflinePageProceed) { | 96 TEST_F(OfflineLoadPageTest, OfflinePageProceed) { |
| 109 // Start a load. | 97 // Start a load. |
| 110 Navigate(kURL1, 1); | 98 Navigate(kURL1, 1); |
| 111 // Load next page. | 99 // Load next page. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // The interstitial should be gone. | 140 // The interstitial should be gone. |
| 153 EXPECT_EQ(CANCEL, user_response()); | 141 EXPECT_EQ(CANCEL, user_response()); |
| 154 EXPECT_FALSE(GetOfflineLoadPage()); | 142 EXPECT_FALSE(GetOfflineLoadPage()); |
| 155 // We did not proceed, the pending entry should be gone. | 143 // We did not proceed, the pending entry should be gone. |
| 156 EXPECT_FALSE(controller().GetPendingEntry()); | 144 EXPECT_FALSE(controller().GetPendingEntry()); |
| 157 // the URL is set back to kURL1. | 145 // the URL is set back to kURL1. |
| 158 EXPECT_EQ(kURL1, web_contents()->GetURL().spec()); | 146 EXPECT_EQ(kURL1, web_contents()->GetURL().spec()); |
| 159 } | 147 } |
| 160 | 148 |
| 161 } // namespace chromeos | 149 } // namespace chromeos |
| OLD | NEW |