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

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

Issue 2484633004: Change Lo-Fi bool to bitmask to support multiple Previews types (Closed)
Patch Set: fix ContentResourceProviderTest Created 3 years, 11 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 "extensions/browser/api/declarative_webrequest/webrequest_condition.h" 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/test/values_test_util.h" 11 #include "base/test/values_test_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "components/url_matcher/url_matcher_constants.h" 13 #include "components/url_matcher/url_matcher_constants.h"
14 #include "content/public/browser/resource_request_info.h" 14 #include "content/public/browser/resource_request_info.h"
15 #include "content/public/common/previews_state.h"
15 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" 16 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
16 #include "net/base/request_priority.h" 17 #include "net/base/request_priority.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_test_util.h" 19 #include "net/url_request/url_request_test_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 using url_matcher::URLMatcher; 22 using url_matcher::URLMatcher;
22 using url_matcher::URLMatcherConditionSet; 23 using url_matcher::URLMatcherConditionSet;
23 24
24 namespace extensions { 25 namespace extensions {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 net::TestURLRequestContext context; 81 net::TestURLRequestContext context;
81 const GURL http_url("http://www.example.com"); 82 const GURL http_url("http://www.example.com");
82 std::unique_ptr<net::URLRequest> match_request( 83 std::unique_ptr<net::URLRequest> match_request(
83 context.CreateRequest(http_url, net::DEFAULT_PRIORITY, NULL)); 84 context.CreateRequest(http_url, net::DEFAULT_PRIORITY, NULL));
84 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST); 85 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST);
85 WebRequestDataWithMatchIds request_data(&data); 86 WebRequestDataWithMatchIds request_data(&data);
86 request_data.url_match_ids = matcher.MatchURL(http_url); 87 request_data.url_match_ids = matcher.MatchURL(http_url);
87 EXPECT_EQ(1u, request_data.url_match_ids.size()); 88 EXPECT_EQ(1u, request_data.url_match_ids.size());
88 content::ResourceRequestInfo::AllocateForTesting( 89 content::ResourceRequestInfo::AllocateForTesting(
89 match_request.get(), content::RESOURCE_TYPE_MAIN_FRAME, 90 match_request.get(), content::RESOURCE_TYPE_MAIN_FRAME,
90 NULL, // context 91 NULL, // context
91 -1, // render_process_id 92 -1, // render_process_id
92 -1, // render_view_id 93 -1, // render_view_id
93 -1, // render_frame_id 94 -1, // render_frame_id
94 true, // is_main_frame 95 true, // is_main_frame
95 false, // parent_is_main_frame 96 false, // parent_is_main_frame
96 true, // allow_download 97 true, // allow_download
97 false, // is_async 98 false, // is_async
98 false); // is_using_lofi 99 content::PREVIEWS_OFF);
99 EXPECT_TRUE(result->IsFulfilled(request_data)); 100 EXPECT_TRUE(result->IsFulfilled(request_data));
100 101
101 const GURL https_url("https://www.example.com"); 102 const GURL https_url("https://www.example.com");
102 std::unique_ptr<net::URLRequest> wrong_resource_type( 103 std::unique_ptr<net::URLRequest> wrong_resource_type(
103 context.CreateRequest(https_url, net::DEFAULT_PRIORITY, NULL)); 104 context.CreateRequest(https_url, net::DEFAULT_PRIORITY, NULL));
104 data.request = wrong_resource_type.get(); 105 data.request = wrong_resource_type.get();
105 request_data.url_match_ids = matcher.MatchURL(http_url); 106 request_data.url_match_ids = matcher.MatchURL(http_url);
106 // Make sure IsFulfilled does not fail because of URL matching. 107 // Make sure IsFulfilled does not fail because of URL matching.
107 EXPECT_EQ(1u, request_data.url_match_ids.size()); 108 EXPECT_EQ(1u, request_data.url_match_ids.size());
108 content::ResourceRequestInfo::AllocateForTesting( 109 content::ResourceRequestInfo::AllocateForTesting(
109 wrong_resource_type.get(), content::RESOURCE_TYPE_SUB_FRAME, 110 wrong_resource_type.get(), content::RESOURCE_TYPE_SUB_FRAME,
110 NULL, // context 111 NULL, // context
111 -1, // render_process_id 112 -1, // render_process_id
112 -1, // render_view_id 113 -1, // render_view_id
113 -1, // render_frame_id 114 -1, // render_frame_id
114 false, // is_main_frame 115 false, // is_main_frame
115 false, // parent_is_main_frame 116 false, // parent_is_main_frame
116 true, // allow_download 117 true, // allow_download
117 false, // is_async 118 false, // is_async
118 false); // is_using_lofi 119 content::PREVIEWS_OFF);
119 EXPECT_FALSE(result->IsFulfilled(request_data)); 120 EXPECT_FALSE(result->IsFulfilled(request_data));
120 } 121 }
121 122
122 TEST(WebRequestConditionTest, CreateConditionFirstPartyForCookies) { 123 TEST(WebRequestConditionTest, CreateConditionFirstPartyForCookies) {
123 // Necessary for TestURLRequest. 124 // Necessary for TestURLRequest.
124 base::MessageLoopForIO message_loop; 125 base::MessageLoopForIO message_loop;
125 URLMatcher matcher; 126 URLMatcher matcher;
126 127
127 std::string error; 128 std::string error;
128 std::unique_ptr<WebRequestCondition> result; 129 std::unique_ptr<WebRequestCondition> result;
(...skipping 20 matching lines...) Expand all
149 std::unique_ptr<net::URLRequest> match_request( 150 std::unique_ptr<net::URLRequest> match_request(
150 context.CreateRequest(http_url, net::DEFAULT_PRIORITY, NULL)); 151 context.CreateRequest(http_url, net::DEFAULT_PRIORITY, NULL));
151 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST); 152 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST);
152 WebRequestDataWithMatchIds request_data(&data); 153 WebRequestDataWithMatchIds request_data(&data);
153 request_data.url_match_ids = matcher.MatchURL(http_url); 154 request_data.url_match_ids = matcher.MatchURL(http_url);
154 EXPECT_EQ(0u, request_data.url_match_ids.size()); 155 EXPECT_EQ(0u, request_data.url_match_ids.size());
155 request_data.first_party_url_match_ids = matcher.MatchURL(first_party_url); 156 request_data.first_party_url_match_ids = matcher.MatchURL(first_party_url);
156 EXPECT_EQ(1u, request_data.first_party_url_match_ids.size()); 157 EXPECT_EQ(1u, request_data.first_party_url_match_ids.size());
157 content::ResourceRequestInfo::AllocateForTesting( 158 content::ResourceRequestInfo::AllocateForTesting(
158 match_request.get(), content::RESOURCE_TYPE_MAIN_FRAME, 159 match_request.get(), content::RESOURCE_TYPE_MAIN_FRAME,
159 NULL, // context 160 NULL, // context
160 -1, // render_process_id 161 -1, // render_process_id
161 -1, // render_view_id 162 -1, // render_view_id
162 -1, // render_frame_id 163 -1, // render_frame_id
163 true, // is_main_frame 164 true, // is_main_frame
164 false, // parent_is_main_frame 165 false, // parent_is_main_frame
165 true, // allow_download 166 true, // allow_download
166 false, // is_async 167 false, // is_async
167 false); // is_using_lofi 168 content::PREVIEWS_OFF);
168 EXPECT_TRUE(result->IsFulfilled(request_data)); 169 EXPECT_TRUE(result->IsFulfilled(request_data));
169 } 170 }
170 171
171 // Conditions without UrlFilter attributes need to be independent of URL 172 // Conditions without UrlFilter attributes need to be independent of URL
172 // matching results. We test here that: 173 // matching results. We test here that:
173 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its 174 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its
174 // attributes are fulfilled. 175 // attributes are fulfilled.
175 // 2. An empty condition (in particular, without UrlFilter attributes) is 176 // 2. An empty condition (in particular, without UrlFilter attributes) is
176 // always fulfilled. 177 // always fulfilled.
177 TEST(WebRequestConditionTest, NoUrlAttributes) { 178 TEST(WebRequestConditionTest, NoUrlAttributes) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // filters. 397 // filters.
397 " \"requestHeaders\": [{}], \n" 398 " \"requestHeaders\": [{}], \n"
398 " \"responseHeaders\": [{}], \n" 399 " \"responseHeaders\": [{}], \n"
399 "}"), 400 "}"),
400 &error); 401 &error);
401 EXPECT_FALSE(error.empty()); 402 EXPECT_FALSE(error.empty());
402 EXPECT_FALSE(result.get()); 403 EXPECT_FALSE(result.get());
403 } 404 }
404 405
405 } // namespace extensions 406 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698