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/browser/tab_contents/interstitial_page.h" | 8 #include "content/browser/tab_contents/interstitial_page.h" |
9 #include "content/browser/tab_contents/test_tab_contents.h" | 9 #include "content/browser/tab_contents/test_tab_contents.h" |
10 #include "content/test/test_browser_thread.h" | 10 #include "content/test/test_browser_thread.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 user_response_ = CANCEL; | 64 user_response_ = CANCEL; |
65 } | 65 } |
66 | 66 |
67 void Navigate(const char* url, int page_id) { | 67 void Navigate(const char* url, int page_id) { |
68 contents()->TestDidNavigate( | 68 contents()->TestDidNavigate( |
69 contents()->GetRenderViewHost(), page_id, GURL(url), | 69 contents()->GetRenderViewHost(), page_id, GURL(url), |
70 content::PAGE_TRANSITION_TYPED); | 70 content::PAGE_TRANSITION_TYPED); |
71 } | 71 } |
72 | 72 |
73 void ShowInterstitial(const char* url) { | 73 void ShowInterstitial(const char* url) { |
74 new TestOfflineLoadPage(contents(), GURL(url), this); | 74 (new TestOfflineLoadPage(contents(), GURL(url), this))->Show(); |
75 } | 75 } |
76 | 76 |
77 // Returns the OfflineLoadPage currently showing or NULL if none is | 77 // Returns the OfflineLoadPage currently showing or NULL if none is |
78 // showing. | 78 // showing. |
79 InterstitialPage* GetOfflineLoadPage() { | 79 InterstitialPage* GetOfflineLoadPage() { |
80 return InterstitialPage::GetInterstitialPage(contents()); | 80 return InterstitialPage::GetInterstitialPage(contents()); |
81 } | 81 } |
82 | 82 |
83 UserResponse user_response() const { return user_response_; } | 83 UserResponse user_response() const { return user_response_; } |
84 | 84 |
85 private: | 85 private: |
86 UserResponse user_response_; | 86 UserResponse user_response_; |
87 content::TestBrowserThread ui_thread_; | 87 content::TestBrowserThread ui_thread_; |
88 content::TestBrowserThread io_thread_; | 88 content::TestBrowserThread io_thread_; |
89 | 89 |
90 // Initializes / shuts down a stub CrosLibrary. | 90 // Initializes / shuts down a stub CrosLibrary. |
91 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; | 91 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; |
92 | 92 |
93 DISALLOW_COPY_AND_ASSIGN(OfflineLoadPageTest); | 93 DISALLOW_COPY_AND_ASSIGN(OfflineLoadPageTest); |
94 }; | 94 }; |
95 | 95 |
96 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { | 96 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { |
97 test_page_->OnBlockingPageComplete(proceed); | 97 test_page_->OnBlockingPageComplete(proceed); |
98 } | 98 } |
99 | 99 |
100 // Tests are disabled due to crash. see crbug.com/113219. | 100 TEST_F(OfflineLoadPageTest, OfflinePageProceed) { |
101 TEST_F(OfflineLoadPageTest, DISABLED_OfflinePageProceed) { | |
102 // Start a load. | 101 // Start a load. |
103 Navigate(kURL1, 1); | 102 Navigate(kURL1, 1); |
104 // Load next page. | 103 // Load next page. |
105 controller().LoadURL(GURL(kURL2), content::Referrer(), | 104 controller().LoadURL(GURL(kURL2), content::Referrer(), |
106 content::PAGE_TRANSITION_TYPED, std::string()); | 105 content::PAGE_TRANSITION_TYPED, std::string()); |
107 | 106 |
108 // Simulate the load causing an offline browsing interstitial page | 107 // Simulate the load causing an offline browsing interstitial page |
109 // to be shown. | 108 // to be shown. |
110 ShowInterstitial(kURL2); | 109 ShowInterstitial(kURL2); |
111 InterstitialPage* interstitial = GetOfflineLoadPage(); | 110 InterstitialPage* interstitial = GetOfflineLoadPage(); |
112 ASSERT_TRUE(interstitial); | 111 ASSERT_TRUE(interstitial); |
113 MessageLoop::current()->RunAllPending(); | 112 MessageLoop::current()->RunAllPending(); |
114 | 113 |
115 // Simulate the user clicking "proceed". | 114 // Simulate the user clicking "proceed". |
116 interstitial->Proceed(); | 115 interstitial->Proceed(); |
117 MessageLoop::current()->RunAllPending(); | 116 MessageLoop::current()->RunAllPending(); |
118 | 117 |
119 EXPECT_EQ(OK, user_response()); | 118 EXPECT_EQ(OK, user_response()); |
120 | 119 |
121 // The URL remains to be URL2. | 120 // The URL remains to be URL2. |
122 EXPECT_EQ(kURL2, contents()->GetURL().spec()); | 121 EXPECT_EQ(kURL2, contents()->GetURL().spec()); |
123 | 122 |
124 // Commit navigation and the interstitial page is gone. | 123 // Commit navigation and the interstitial page is gone. |
125 Navigate(kURL2, 2); | 124 Navigate(kURL2, 2); |
126 EXPECT_FALSE(GetOfflineLoadPage()); | 125 EXPECT_FALSE(GetOfflineLoadPage()); |
127 } | 126 } |
128 | 127 |
129 // Tests showing an offline page and not proceeding. | 128 // Tests showing an offline page and not proceeding. |
130 TEST_F(OfflineLoadPageTest, DISABLED_OfflinePageDontProceed) { | 129 TEST_F(OfflineLoadPageTest, OfflinePageDontProceed) { |
131 // Start a load. | 130 // Start a load. |
132 Navigate(kURL1, 1); | 131 Navigate(kURL1, 1); |
133 controller().LoadURL(GURL(kURL2), content::Referrer(), | 132 controller().LoadURL(GURL(kURL2), content::Referrer(), |
134 content::PAGE_TRANSITION_TYPED, std::string()); | 133 content::PAGE_TRANSITION_TYPED, std::string()); |
135 | 134 |
136 // Simulate the load causing an offline interstitial page to be shown. | 135 // Simulate the load causing an offline interstitial page to be shown. |
137 ShowInterstitial(kURL2); | 136 ShowInterstitial(kURL2); |
138 InterstitialPage* interstitial = GetOfflineLoadPage(); | 137 InterstitialPage* interstitial = GetOfflineLoadPage(); |
139 ASSERT_TRUE(interstitial); | 138 ASSERT_TRUE(interstitial); |
140 MessageLoop::current()->RunAllPending(); | 139 MessageLoop::current()->RunAllPending(); |
141 | 140 |
142 // Simulate the user clicking "don't proceed". | 141 // Simulate the user clicking "don't proceed". |
143 interstitial->DontProceed(); | 142 interstitial->DontProceed(); |
144 | 143 |
145 // The interstitial should be gone. | 144 // The interstitial should be gone. |
146 EXPECT_EQ(CANCEL, user_response()); | 145 EXPECT_EQ(CANCEL, user_response()); |
147 EXPECT_FALSE(GetOfflineLoadPage()); | 146 EXPECT_FALSE(GetOfflineLoadPage()); |
148 // We did not proceed, the pending entry should be gone. | 147 // We did not proceed, the pending entry should be gone. |
149 EXPECT_FALSE(controller().GetPendingEntry()); | 148 EXPECT_FALSE(controller().GetPendingEntry()); |
150 // the URL is set back to kURL1. | 149 // the URL is set back to kURL1. |
151 EXPECT_EQ(kURL1, contents()->GetURL().spec()); | 150 EXPECT_EQ(kURL1, contents()->GetURL().spec()); |
152 } | 151 } |
153 | 152 |
154 } // namespace chromeos | 153 } // namespace chromeos |
OLD | NEW |