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

Side by Side Diff: chrome/browser/net/chrome_network_delegate_unittest.cc

Issue 51953002: [Net] Add a priority parameter to URLRequest's constructor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error from rebase Created 7 years, 1 month 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 | Annotate | Revision Log
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/net/chrome_network_delegate.h" 5 #include "chrome/browser/net/chrome_network_delegate.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_member.h" 10 #include "base/prefs/pref_member.h"
11 #include "chrome/browser/content_settings/cookie_settings.h" 11 #include "chrome/browser/content_settings/cookie_settings.h"
12 #include "chrome/browser/extensions/event_router_forwarder.h" 12 #include "chrome/browser/extensions/event_router_forwarder.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/testing_pref_service_syncable.h" 15 #include "chrome/test/base/testing_pref_service_syncable.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "net/base/completion_callback.h" 18 #include "net/base/completion_callback.h"
19 #include "net/base/request_priority.h"
19 #include "net/url_request/url_request.h" 20 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 class ChromeNetworkDelegateTest : public testing::Test { 24 class ChromeNetworkDelegateTest : public testing::Test {
24 protected: 25 protected:
25 ChromeNetworkDelegateTest() 26 ChromeNetworkDelegateTest()
26 : forwarder_(new extensions::EventRouterForwarder()) { 27 : forwarder_(new extensions::EventRouterForwarder()) {
27 } 28 }
28 29
(...skipping 11 matching lines...) Expand all
40 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { 41 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() {
41 return make_scoped_ptr( 42 return make_scoped_ptr(
42 new ChromeNetworkDelegate(forwarder_.get(), &pref_member_)); 43 new ChromeNetworkDelegate(forwarder_.get(), &pref_member_));
43 } 44 }
44 45
45 // Implementation moved here for access to private bits. 46 // Implementation moved here for access to private bits.
46 void NeverThrottleLogicImpl() { 47 void NeverThrottleLogicImpl() {
47 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate()); 48 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate());
48 49
49 net::TestURLRequestContext context; 50 net::TestURLRequestContext context;
50 net::TestURLRequest extension_request( 51 net::TestURLRequest extension_request(GURL("http://example.com/"),
51 GURL("http://example.com/"), NULL, &context, NULL); 52 net::DEFAULT_PRIORITY,
53 NULL,
54 &context,
55 NULL);
52 extension_request.set_first_party_for_cookies( 56 extension_request.set_first_party_for_cookies(
53 GURL("chrome-extension://abcdef/bingo.html")); 57 GURL("chrome-extension://abcdef/bingo.html"));
54 net::TestURLRequest web_page_request( 58 net::TestURLRequest web_page_request(GURL("http://example.com/"),
55 GURL("http://example.com/"), NULL, &context, NULL); 59 net::DEFAULT_PRIORITY,
60 NULL,
61 &context,
62 NULL);
56 web_page_request.set_first_party_for_cookies( 63 web_page_request.set_first_party_for_cookies(
57 GURL("http://example.com/helloworld.html")); 64 GURL("http://example.com/helloworld.html"));
58 65
59 ASSERT_TRUE(delegate->OnCanThrottleRequest(extension_request)); 66 ASSERT_TRUE(delegate->OnCanThrottleRequest(extension_request));
60 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); 67 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request));
61 68
62 delegate->NeverThrottleRequests(); 69 delegate->NeverThrottleRequests();
63 ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_); 70 ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_);
64 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request)); 71 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request));
65 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); 72 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 126 }
120 127
121 // Does a request using the |url_string| URL and verifies that the expected 128 // Does a request using the |url_string| URL and verifies that the expected
122 // string is equal to the query part (between ? and #) of the final url of 129 // string is equal to the query part (between ? and #) of the final url of
123 // that request. 130 // that request.
124 void CheckAddedParameters(const std::string& url_string, 131 void CheckAddedParameters(const std::string& url_string,
125 const std::string& expected_query_parameters) { 132 const std::string& expected_query_parameters) {
126 // Show the URL in the trace so we know where we failed. 133 // Show the URL in the trace so we know where we failed.
127 SCOPED_TRACE(url_string); 134 SCOPED_TRACE(url_string);
128 135
129 net::TestURLRequest request( 136 net::TestURLRequest request(GURL(url_string),
130 GURL(url_string), &delegate_, &context_, network_delegate_); 137 net::DEFAULT_PRIORITY,
138 &delegate_,
139 &context_,
140 network_delegate_);
131 141
132 request.Start(); 142 request.Start();
133 base::MessageLoop::current()->RunUntilIdle(); 143 base::MessageLoop::current()->RunUntilIdle();
134 144
135 EXPECT_EQ(expected_query_parameters, request.url().query()); 145 EXPECT_EQ(expected_query_parameters, request.url().query());
136 } 146 }
137 147
138 private: 148 private:
139 content::TestBrowserThreadBundle thread_bundle_; 149 content::TestBrowserThreadBundle thread_bundle_;
140 scoped_refptr<extensions::EventRouterForwarder> forwarder_; 150 scoped_refptr<extensions::EventRouterForwarder> forwarder_;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 387
378 cookie_settings_->SetCookieSetting( 388 cookie_settings_->SetCookieSetting(
379 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), 389 ContentSettingsPattern::FromURL(kBlockedFirstPartySite),
380 ContentSettingsPattern::Wildcard(), 390 ContentSettingsPattern::Wildcard(),
381 CONTENT_SETTING_BLOCK); 391 CONTENT_SETTING_BLOCK);
382 // Privacy mode is disabled as kAllowedSite is still getting cookies 392 // Privacy mode is disabled as kAllowedSite is still getting cookies
383 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 393 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
384 kBlockedFirstPartySite)); 394 kBlockedFirstPartySite));
385 } 395 }
386 396
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698