Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Side by Side Diff: chrome/browser/chromeos/offline/offline_load_page_unittest.cc

Issue 1237353002: Remove Old ChromeOS Offline Error Page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/offline/offline_load_page.h"
6 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
7 #include "content/public/browser/interstitial_page.h"
8 #include "content/public/browser/navigation_controller.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/test/web_contents_tester.h"
11
12 using content::InterstitialPage;
13 using content::WebContents;
14 using content::WebContentsTester;
15
16 static const char kURL1[] = "http://www.google.com/";
17 static const char kURL2[] = "http://www.gmail.com/";
18
19 namespace chromeos {
20
21 class OfflineLoadPageTest;
22
23 // An OfflineLoadPage class that does not create windows.
24 class TestOfflineLoadPage : public chromeos::OfflineLoadPage {
25 public:
26 TestOfflineLoadPage(WebContents* web_contents,
27 const GURL& url,
28 OfflineLoadPageTest* test_page)
29 : chromeos::OfflineLoadPage(web_contents, url, CompletionCallback()),
30 test_page_(test_page) {
31 interstitial_page_->DontCreateViewForTesting();
32 }
33
34 // chromeos::OfflineLoadPage override.
35 void NotifyBlockingPageComplete(bool proceed) override;
36
37 private:
38 OfflineLoadPageTest* test_page_;
39
40 DISALLOW_COPY_AND_ASSIGN(TestOfflineLoadPage);
41 };
42
43 class OfflineLoadPageTest : public ChromeRenderViewHostTestHarness {
44 public:
45 // The decision the user made.
46 enum UserResponse {
47 PENDING,
48 OK,
49 CANCEL
50 };
51
52 void SetUp() override {
53 ChromeRenderViewHostTestHarness::SetUp();
54 user_response_ = PENDING;
55 }
56
57 void OnBlockingPageComplete(bool proceed) {
58 if (proceed)
59 user_response_ = OK;
60 else
61 user_response_ = CANCEL;
62 }
63
64 void Navigate(const char* url,
65 int page_id,
66 int nav_entry_id,
67 bool did_create_new_entry) {
68 WebContentsTester::For(web_contents())
69 ->TestDidNavigate(web_contents()->GetMainFrame(), page_id, nav_entry_id,
70 did_create_new_entry, GURL(url),
71 ui::PAGE_TRANSITION_TYPED);
72 }
73
74 void ShowInterstitial(const char* url) {
75 (new TestOfflineLoadPage(web_contents(), GURL(url), this))->Show();
76 }
77
78 // Returns the OfflineLoadPage currently showing or NULL if none is
79 // showing.
80 InterstitialPage* GetOfflineLoadPage() {
81 return InterstitialPage::GetInterstitialPage(web_contents());
82 }
83
84 UserResponse user_response() const { return user_response_; }
85
86 private:
87 friend class TestOfflineLoadPage;
88
89 UserResponse user_response_;
90 };
91
92 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) {
93 test_page_->OnBlockingPageComplete(proceed);
94 }
95
96 TEST_F(OfflineLoadPageTest, OfflinePageProceed) {
97 // Start a load.
98 Navigate(kURL1, 1, 0, true);
99 // Load next page.
100 controller().LoadURL(GURL(kURL2), content::Referrer(),
101 ui::PAGE_TRANSITION_TYPED, std::string());
102
103 // Simulate the load causing an offline browsing interstitial page
104 // to be shown.
105 ShowInterstitial(kURL2);
106 InterstitialPage* interstitial = GetOfflineLoadPage();
107 ASSERT_TRUE(interstitial);
108 base::MessageLoop::current()->RunUntilIdle();
109
110 // Simulate the user clicking "proceed".
111 interstitial->Proceed();
112 base::MessageLoop::current()->RunUntilIdle();
113
114 EXPECT_EQ(OK, user_response());
115
116 // The URL remains to be URL2.
117 EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec());
118
119 // Commit navigation and the interstitial page is gone.
120 Navigate(kURL2, 2, 0, true);
121 EXPECT_FALSE(GetOfflineLoadPage());
122 }
123
124 // Tests showing an offline page and not proceeding.
125 TEST_F(OfflineLoadPageTest, OfflinePageDontProceed) {
126 // Start a load.
127 Navigate(kURL1, 1, 0, true);
128 controller().LoadURL(GURL(kURL2), content::Referrer(),
129 ui::PAGE_TRANSITION_TYPED, std::string());
130
131 // Simulate the load causing an offline interstitial page to be shown.
132 ShowInterstitial(kURL2);
133 InterstitialPage* interstitial = GetOfflineLoadPage();
134 ASSERT_TRUE(interstitial);
135 base::MessageLoop::current()->RunUntilIdle();
136
137 // Simulate the user clicking "don't proceed".
138 interstitial->DontProceed();
139
140 // The interstitial should be gone.
141 EXPECT_EQ(CANCEL, user_response());
142 EXPECT_FALSE(GetOfflineLoadPage());
143 // We did not proceed, the pending entry should be gone.
144 EXPECT_FALSE(controller().GetPendingEntry());
145 // the URL is set back to kURL1.
146 EXPECT_EQ(kURL1, web_contents()->GetLastCommittedURL().spec());
147 }
148
149 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698