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

Side by Side Diff: components/web_restrictions/browser/web_restrictions_resource_throttle_unittest.cc

Issue 1890203002: Implement Web Restrictions in WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Manual rebase, no other changes Created 4 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "components/web_restrictions/browser/mock_web_restrictions_client.h" 7 #include "components/web_restrictions/browser/mock_web_restrictions_client.h"
8 #include "components/web_restrictions/browser/web_restrictions_client.h" 8 #include "components/web_restrictions/browser/web_restrictions_client.h"
9 #include "components/web_restrictions/browser/web_restrictions_resource_throttle .h" 9 #include "components/web_restrictions/browser/web_restrictions_resource_throttle .h"
10 #include "content/public/browser/resource_controller.h" 10 #include "content/public/browser/resource_controller.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // first to ensure that everything is initialized. 116 // first to ensure that everything is initialized.
117 StartProvider(); 117 StartProvider();
118 // Now the real test. 118 // Now the real test.
119 WebRestrictionsResourceThrottle throttle( 119 WebRestrictionsResourceThrottle throttle(
120 &provider_, GURL("http://example.com/sub"), false); 120 &provider_, GURL("http://example.com/sub"), false);
121 base::RunLoop test_run_loop; 121 base::RunLoop test_run_loop;
122 TestResourceController test_controller(test_run_loop.QuitClosure()); 122 TestResourceController test_controller(test_run_loop.QuitClosure());
123 throttle.set_controller_for_testing(&test_controller); 123 throttle.set_controller_for_testing(&test_controller);
124 bool defer; 124 bool defer;
125 throttle.WillStartRequest(&defer); 125 throttle.WillStartRequest(&defer);
126 EXPECT_FALSE(defer); 126 ASSERT_FALSE(defer);
127 } 127 }
128 128
129 TEST_F(WebRestrictionsResourceThrottleTest, WillRedirectRequest_KnownUrl) { 129 TEST_F(WebRestrictionsResourceThrottleTest, WillRedirectRequest_KnownUrl) {
130 // Set up a cached url. 130 // Set up a cached url.
131 StartProvider(); 131 StartProvider();
132 // Using the same URL should not be deferred 132 // Using the same URL should not be deferred
133 net::RedirectInfo redirect; 133 net::RedirectInfo redirect;
134 redirect.new_url = GURL("http://example.com"); 134 redirect.new_url = GURL("http://example.com");
135 bool defer; 135 bool defer;
136 throttle_.WillRedirectRequest(redirect, &defer); 136 throttle_.WillRedirectRequest(redirect, &defer);
137 EXPECT_FALSE(defer); 137 ASSERT_FALSE(defer);
138 } 138 }
139 139
140 TEST_F(WebRestrictionsResourceThrottleTest, WillRedirectRequest_NewUrl) { 140 TEST_F(WebRestrictionsResourceThrottleTest, WillRedirectRequest_NewUrl) {
141 // Set up a cached url. 141 // Set up a cached url.
142 StartProvider(); 142 StartProvider();
143 // Using a different URL should be deferred 143 // Using a different URL should be deferred
144 net::RedirectInfo redirect; 144 net::RedirectInfo redirect;
145 redirect.new_url = GURL("http://example.com/2"); 145 redirect.new_url = GURL("http://example.com/2");
146 base::RunLoop test_run_loop; 146 base::RunLoop test_run_loop;
147 TestResourceController test_controller(test_run_loop.QuitClosure()); 147 TestResourceController test_controller(test_run_loop.QuitClosure());
148 throttle_.set_controller_for_testing(&test_controller); 148 throttle_.set_controller_for_testing(&test_controller);
149 bool defer; 149 bool defer;
150 throttle_.WillRedirectRequest(redirect, &defer); 150 throttle_.WillRedirectRequest(redirect, &defer);
151 EXPECT_TRUE(defer); 151 ASSERT_TRUE(defer);
152 // If we don't wait for the callback it may happen after the exit, which 152 // If we don't wait for the callback it may happen after the exit, which
153 // results in accesses the redirect_url after the stack frame is freed. 153 // results in accesses the redirect_url after the stack frame is freed.
154 test_run_loop.Run(); 154 test_run_loop.Run();
155 } 155 }
156 156
157 } // namespace web_restrictions 157 } // namespace web_restrictions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698