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

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

Issue 562603002: Move PageTransition from //content/public/common to //ui/base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 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
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/offline/offline_load_page.h" 5 #include "chrome/browser/chromeos/offline/offline_load_page.h"
6 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 6 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
7 #include "content/public/browser/interstitial_page.h" 7 #include "content/public/browser/interstitial_page.h"
8 #include "content/public/browser/navigation_controller.h" 8 #include "content/public/browser/navigation_controller.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "content/public/test/web_contents_tester.h" 10 #include "content/public/test/web_contents_tester.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 void OnBlockingPageComplete(bool proceed) { 57 void OnBlockingPageComplete(bool proceed) {
58 if (proceed) 58 if (proceed)
59 user_response_ = OK; 59 user_response_ = OK;
60 else 60 else
61 user_response_ = CANCEL; 61 user_response_ = CANCEL;
62 } 62 }
63 63
64 void Navigate(const char* url, int page_id) { 64 void Navigate(const char* url, int page_id) {
65 WebContentsTester::For(web_contents())->TestDidNavigate( 65 WebContentsTester::For(web_contents())->TestDidNavigate(
66 web_contents()->GetMainFrame(), page_id, GURL(url), 66 web_contents()->GetMainFrame(), page_id, GURL(url),
67 content::PAGE_TRANSITION_TYPED); 67 ui::PAGE_TRANSITION_TYPED);
68 } 68 }
69 69
70 void ShowInterstitial(const char* url) { 70 void ShowInterstitial(const char* url) {
71 (new TestOfflineLoadPage(web_contents(), GURL(url), this))->Show(); 71 (new TestOfflineLoadPage(web_contents(), GURL(url), this))->Show();
72 } 72 }
73 73
74 // Returns the OfflineLoadPage currently showing or NULL if none is 74 // Returns the OfflineLoadPage currently showing or NULL if none is
75 // showing. 75 // showing.
76 InterstitialPage* GetOfflineLoadPage() { 76 InterstitialPage* GetOfflineLoadPage() {
77 return InterstitialPage::GetInterstitialPage(web_contents()); 77 return InterstitialPage::GetInterstitialPage(web_contents());
78 } 78 }
79 79
80 UserResponse user_response() const { return user_response_; } 80 UserResponse user_response() const { return user_response_; }
81 81
82 private: 82 private:
83 friend class TestOfflineLoadPage; 83 friend class TestOfflineLoadPage;
84 84
85 UserResponse user_response_; 85 UserResponse user_response_;
86 }; 86 };
87 87
88 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { 88 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) {
89 test_page_->OnBlockingPageComplete(proceed); 89 test_page_->OnBlockingPageComplete(proceed);
90 } 90 }
91 91
92 TEST_F(OfflineLoadPageTest, OfflinePageProceed) { 92 TEST_F(OfflineLoadPageTest, OfflinePageProceed) {
93 // Start a load. 93 // Start a load.
94 Navigate(kURL1, 1); 94 Navigate(kURL1, 1);
95 // Load next page. 95 // Load next page.
96 controller().LoadURL(GURL(kURL2), content::Referrer(), 96 controller().LoadURL(GURL(kURL2), content::Referrer(),
97 content::PAGE_TRANSITION_TYPED, std::string()); 97 ui::PAGE_TRANSITION_TYPED, std::string());
98 98
99 // Simulate the load causing an offline browsing interstitial page 99 // Simulate the load causing an offline browsing interstitial page
100 // to be shown. 100 // to be shown.
101 ShowInterstitial(kURL2); 101 ShowInterstitial(kURL2);
102 InterstitialPage* interstitial = GetOfflineLoadPage(); 102 InterstitialPage* interstitial = GetOfflineLoadPage();
103 ASSERT_TRUE(interstitial); 103 ASSERT_TRUE(interstitial);
104 base::MessageLoop::current()->RunUntilIdle(); 104 base::MessageLoop::current()->RunUntilIdle();
105 105
106 // Simulate the user clicking "proceed". 106 // Simulate the user clicking "proceed".
107 interstitial->Proceed(); 107 interstitial->Proceed();
108 base::MessageLoop::current()->RunUntilIdle(); 108 base::MessageLoop::current()->RunUntilIdle();
109 109
110 EXPECT_EQ(OK, user_response()); 110 EXPECT_EQ(OK, user_response());
111 111
112 // The URL remains to be URL2. 112 // The URL remains to be URL2.
113 EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec()); 113 EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec());
114 114
115 // Commit navigation and the interstitial page is gone. 115 // Commit navigation and the interstitial page is gone.
116 Navigate(kURL2, 2); 116 Navigate(kURL2, 2);
117 EXPECT_FALSE(GetOfflineLoadPage()); 117 EXPECT_FALSE(GetOfflineLoadPage());
118 } 118 }
119 119
120 // Tests showing an offline page and not proceeding. 120 // Tests showing an offline page and not proceeding.
121 TEST_F(OfflineLoadPageTest, OfflinePageDontProceed) { 121 TEST_F(OfflineLoadPageTest, OfflinePageDontProceed) {
122 // Start a load. 122 // Start a load.
123 Navigate(kURL1, 1); 123 Navigate(kURL1, 1);
124 controller().LoadURL(GURL(kURL2), content::Referrer(), 124 controller().LoadURL(GURL(kURL2), content::Referrer(),
125 content::PAGE_TRANSITION_TYPED, std::string()); 125 ui::PAGE_TRANSITION_TYPED, std::string());
126 126
127 // Simulate the load causing an offline interstitial page to be shown. 127 // Simulate the load causing an offline interstitial page to be shown.
128 ShowInterstitial(kURL2); 128 ShowInterstitial(kURL2);
129 InterstitialPage* interstitial = GetOfflineLoadPage(); 129 InterstitialPage* interstitial = GetOfflineLoadPage();
130 ASSERT_TRUE(interstitial); 130 ASSERT_TRUE(interstitial);
131 base::MessageLoop::current()->RunUntilIdle(); 131 base::MessageLoop::current()->RunUntilIdle();
132 132
133 // Simulate the user clicking "don't proceed". 133 // Simulate the user clicking "don't proceed".
134 interstitial->DontProceed(); 134 interstitial->DontProceed();
135 135
136 // The interstitial should be gone. 136 // The interstitial should be gone.
137 EXPECT_EQ(CANCEL, user_response()); 137 EXPECT_EQ(CANCEL, user_response());
138 EXPECT_FALSE(GetOfflineLoadPage()); 138 EXPECT_FALSE(GetOfflineLoadPage());
139 // We did not proceed, the pending entry should be gone. 139 // We did not proceed, the pending entry should be gone.
140 EXPECT_FALSE(controller().GetPendingEntry()); 140 EXPECT_FALSE(controller().GetPendingEntry());
141 // the URL is set back to kURL1. 141 // the URL is set back to kURL1.
142 EXPECT_EQ(kURL1, web_contents()->GetLastCommittedURL().spec()); 142 EXPECT_EQ(kURL1, web_contents()->GetLastCommittedURL().spec());
143 } 143 }
144 144
145 } // namespace chromeos 145 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698