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

Side by Side Diff: extensions/browser/api/declarative_webrequest/webrequest_condition_unittest.cc

Issue 624073002: Add is_main_frame and parent_is_main_frame to ResourceRequestInfo::AllocateForTesting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile extensions_unittests Created 6 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
« no previous file with comments | « extensions/browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "extensions/browser/api/declarative_webrequest/webrequest_condition.h" 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const GURL http_url("http://www.example.com"); 82 const GURL http_url("http://www.example.com");
83 scoped_ptr<net::URLRequest> match_request(context.CreateRequest( 83 scoped_ptr<net::URLRequest> match_request(context.CreateRequest(
84 http_url, net::DEFAULT_PRIORITY, NULL, NULL)); 84 http_url, net::DEFAULT_PRIORITY, NULL, NULL));
85 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST); 85 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST);
86 WebRequestDataWithMatchIds request_data(&data); 86 WebRequestDataWithMatchIds request_data(&data);
87 request_data.url_match_ids = matcher.MatchURL(http_url); 87 request_data.url_match_ids = matcher.MatchURL(http_url);
88 EXPECT_EQ(1u, request_data.url_match_ids.size()); 88 EXPECT_EQ(1u, request_data.url_match_ids.size());
89 content::ResourceRequestInfo::AllocateForTesting( 89 content::ResourceRequestInfo::AllocateForTesting(
90 match_request.get(), 90 match_request.get(),
91 content::RESOURCE_TYPE_MAIN_FRAME, 91 content::RESOURCE_TYPE_MAIN_FRAME,
92 NULL, 92 NULL, // context
93 -1, 93 -1, // render_process_id
94 -1, 94 -1, // render_view_id
95 -1, 95 -1, // render_frame_id
96 false); 96 true, // is_main_frame
97 false, // parent_is_main_frame
98 false); // is_async
97 EXPECT_TRUE(result->IsFulfilled(request_data)); 99 EXPECT_TRUE(result->IsFulfilled(request_data));
98 100
99 const GURL https_url("https://www.example.com"); 101 const GURL https_url("https://www.example.com");
100 scoped_ptr<net::URLRequest> wrong_resource_type(context.CreateRequest( 102 scoped_ptr<net::URLRequest> wrong_resource_type(context.CreateRequest(
101 https_url, net::DEFAULT_PRIORITY, NULL, NULL)); 103 https_url, net::DEFAULT_PRIORITY, NULL, NULL));
102 data.request = wrong_resource_type.get(); 104 data.request = wrong_resource_type.get();
103 request_data.url_match_ids = matcher.MatchURL(http_url); 105 request_data.url_match_ids = matcher.MatchURL(http_url);
104 // Make sure IsFulfilled does not fail because of URL matching. 106 // Make sure IsFulfilled does not fail because of URL matching.
105 EXPECT_EQ(1u, request_data.url_match_ids.size()); 107 EXPECT_EQ(1u, request_data.url_match_ids.size());
106 content::ResourceRequestInfo::AllocateForTesting( 108 content::ResourceRequestInfo::AllocateForTesting(
107 wrong_resource_type.get(), 109 wrong_resource_type.get(),
108 content::RESOURCE_TYPE_SUB_FRAME, 110 content::RESOURCE_TYPE_SUB_FRAME,
109 NULL, 111 NULL, // context
110 -1, 112 -1, // render_process_id
111 -1, 113 -1, // render_view_id
112 -1, 114 -1, // render_frame_id
113 false); 115 false, // is_main_frame
116 false, // parent_is_main_frame
117 false); // is_async
114 EXPECT_FALSE(result->IsFulfilled(request_data)); 118 EXPECT_FALSE(result->IsFulfilled(request_data));
115 } 119 }
116 120
117 TEST(WebRequestConditionTest, CreateConditionFirstPartyForCookies) { 121 TEST(WebRequestConditionTest, CreateConditionFirstPartyForCookies) {
118 // Necessary for TestURLRequest. 122 // Necessary for TestURLRequest.
119 base::MessageLoopForIO message_loop; 123 base::MessageLoopForIO message_loop;
120 URLMatcher matcher; 124 URLMatcher matcher;
121 125
122 std::string error; 126 std::string error;
123 scoped_ptr<WebRequestCondition> result; 127 scoped_ptr<WebRequestCondition> result;
(...skipping 21 matching lines...) Expand all
145 http_url, net::DEFAULT_PRIORITY, NULL, NULL)); 149 http_url, net::DEFAULT_PRIORITY, NULL, NULL));
146 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST); 150 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST);
147 WebRequestDataWithMatchIds request_data(&data); 151 WebRequestDataWithMatchIds request_data(&data);
148 request_data.url_match_ids = matcher.MatchURL(http_url); 152 request_data.url_match_ids = matcher.MatchURL(http_url);
149 EXPECT_EQ(0u, request_data.url_match_ids.size()); 153 EXPECT_EQ(0u, request_data.url_match_ids.size());
150 request_data.first_party_url_match_ids = matcher.MatchURL(first_party_url); 154 request_data.first_party_url_match_ids = matcher.MatchURL(first_party_url);
151 EXPECT_EQ(1u, request_data.first_party_url_match_ids.size()); 155 EXPECT_EQ(1u, request_data.first_party_url_match_ids.size());
152 content::ResourceRequestInfo::AllocateForTesting( 156 content::ResourceRequestInfo::AllocateForTesting(
153 match_request.get(), 157 match_request.get(),
154 content::RESOURCE_TYPE_MAIN_FRAME, 158 content::RESOURCE_TYPE_MAIN_FRAME,
155 NULL, 159 NULL, // context
156 -1, 160 -1, // render_process_id
157 -1, 161 -1, // render_view_id
158 -1, 162 -1, // render_frame_id
159 false); 163 true, // is_main_frame
164 false, // parent_is_main_frame
165 false); // is_async
160 EXPECT_TRUE(result->IsFulfilled(request_data)); 166 EXPECT_TRUE(result->IsFulfilled(request_data));
161 } 167 }
162 168
163 // Conditions without UrlFilter attributes need to be independent of URL 169 // Conditions without UrlFilter attributes need to be independent of URL
164 // matching results. We test here that: 170 // matching results. We test here that:
165 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its 171 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its
166 // attributes are fulfilled. 172 // attributes are fulfilled.
167 // 2. An empty condition (in particular, without UrlFilter attributes) is 173 // 2. An empty condition (in particular, without UrlFilter attributes) is
168 // always fulfilled. 174 // always fulfilled.
169 TEST(WebRequestConditionTest, NoUrlAttributes) { 175 TEST(WebRequestConditionTest, NoUrlAttributes) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 // filters. 394 // filters.
389 " \"requestHeaders\": [{}], \n" 395 " \"requestHeaders\": [{}], \n"
390 " \"responseHeaders\": [{}], \n" 396 " \"responseHeaders\": [{}], \n"
391 "}"), 397 "}"),
392 &error); 398 &error);
393 EXPECT_FALSE(error.empty()); 399 EXPECT_FALSE(error.empty());
394 EXPECT_FALSE(result.get()); 400 EXPECT_FALSE(result.get());
395 } 401 }
396 402
397 } // namespace extensions 403 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698