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

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

Issue 380003002: Improve testing for SDCH. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Next round of comments incorporated. Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // End-to-end SDCH tests. Uses the embedded test server to return SDCH
6 // results
7
8 #include "base/base64.h"
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/command_line.h"
12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/path_service.h"
15 #include "base/run_loop.h"
16 #include "base/strings/string_tokenizer.h"
17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h"
19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/browsing_data/browsing_data_helper.h"
21 #include "chrome/browser/browsing_data/browsing_data_remover.h"
22 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_tabstrip.h"
27 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/common/chrome_paths.h"
30 #include "chrome/test/base/in_process_browser_test.h"
31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/common/content_switches.h"
33 #include "content/public/test/browser_test_utils.h"
34 #include "content/public/test/test_utils.h"
35 #include "crypto/sha2.h"
36 #include "net/base/sdch_manager.h"
37 #include "net/http/http_response_headers.h"
38 #include "net/test/embedded_test_server/embedded_test_server.h"
39 #include "net/test/embedded_test_server/http_request.h"
40 #include "net/test/embedded_test_server/http_response.h"
41 #include "net/url_request/url_fetcher.h"
42 #include "net/url_request/url_fetcher_delegate.h"
43 #include "net/url_request/url_request_context.h"
44 #include "net/url_request/url_request_context_getter.h"
45 #include "sdch/open-vcdiff/src/google/vcencoder.h"
46 #include "testing/gtest/include/gtest/gtest.h"
47
48 namespace {
49
50 typedef std::vector<net::test_server::HttpRequest> RequestVector;
51 typedef std::map<std::string, std::string> HttpRequestHeaderMap;
52
53 // Credit Alfred, Lord Tennyson
54 static const char kSampleData[] = "<html><body><pre>"
55 "There lies the port; the vessel puffs her sail:\n"
56 "There gloom the dark, broad seas. My mariners,\n"
57 "Souls that have toil'd, and wrought, and thought with me—\n"
58 "That ever with a frolic welcome took\n"
59 "The thunder and the sunshine, and opposed\n"
60 "Free hearts, free foreheads—you and I are old;\n"
61 "Old age hath yet his honour and his toil;\n"
62 "Death closes all: but something ere the end,\n"
63 "Some work of noble note, may yet be done,\n"
64 "Not unbecoming men that strove with Gods.\n"
65 "The lights begin to twinkle from the rocks:\n"
66 "The long day wanes: the slow moon climbs: the deep\n"
67 "Moans round with many voices. Come, my friends,\n"
68 "'T is not too late to seek a newer world.\n"
69 "Push off, and sitting well in order smite\n"
70 "The sounding furrows; for my purpose holds\n"
71 "To sail beyond the sunset, and the baths\n"
72 "Of all the western stars, until I die.\n"
73 "It may be that the gulfs will wash us down:\n"
74 "It may be we shall touch the Happy Isles,\n"
75 "And see the great Achilles, whom we knew.\n"
76 "Tho' much is taken, much abides; and tho'\n"
77 "We are not now that strength which in old days\n"
78 "Moved earth and heaven, that which we are, we are;\n"
79 "One equal temper of heroic hearts,\n"
80 "Made weak by time and fate, but strong in will\n"
81 "To strive, to seek, to find, and not to yield.\n"
82 "</pre></body></html>";
83
84 // Random selection of lines from above, to allow some encoding, but
85 // not a trivial encoding.
86 static const char kDictionaryContents[] =
87 "The thunder and the sunshine, and opposed\n"
88 "To sail beyond the sunset, and the baths\n"
89 "Of all the western stars, until I die.\n"
90 "Made weak by time and fate, but strong in will\n"
91 "Moans round with many voices. Come, my friends,\n"
92 "The lights begin to twinkle from the rocks:";
93
94 static const char kDictionaryURLPath[] = "/dict";
95 static const char kDataURLPath[] = "/data";
96
97 // Scans in a case-insensitive way for |header| in |map|,
98 // returning true if found and setting |*value| to the value
99 // of that header. Does not handle multiple instances of the same
100 // header.
101 bool GetRequestHeader(const HttpRequestHeaderMap& map,
102 const char* header,
103 std::string* value) {
104 for (HttpRequestHeaderMap::const_iterator it = map.begin();
105 it != map.end(); ++it) {
106
107 if (!base::strcasecmp(it->first.c_str(), header)) {
108 *value = it->second;
109 return true;
110 }
111 }
112 return false;
113 }
114
115 // Do a URL-safe base64 encoding. See the SDCH spec "Dictionary Identifier"
116 // section, and RFC 3548 section 4.
117 void SafeBase64Encode(const std::string& input_value, std::string* output) {
118 DCHECK(output);
119 base::Base64Encode(input_value, output);
120 std::replace(output->begin(), output->end(), '+', '-');
121 std::replace(output->begin(), output->end(), '/', '_');
122 }
123
124 // Class that bundles responses for an EmbeddedTestServer().
125 // Dictionary is at <domain>/dict, data at <domain>/data.
126 // The data is sent SDCH encoded if that's allowed by protoocol.
127 class SdchResponseHandler {
128 public:
129 // Do initial preparation so that SDCH requests can be handled.
130 explicit SdchResponseHandler(std::string domain)
131 : cache_sdch_response_(false),
132 weak_ptr_factory_(this) {
133 // Dictionary
134 sdch_dictionary_contents_ = "Domain: ";
135 sdch_dictionary_contents_ += domain;
136 sdch_dictionary_contents_ += "\n\n";
137 sdch_dictionary_contents_ += kDictionaryContents;
138
139 // Dictionary hash for client and server.
140 char binary_hash[32];
141 crypto::SHA256HashString(sdch_dictionary_contents_, binary_hash,
142 sizeof(binary_hash));
143 SafeBase64Encode(std::string(&binary_hash[0], 6), &dictionary_client_hash_);
144 SafeBase64Encode(std::string(&binary_hash[6], 6), &dictionary_server_hash_);
145
146 // Encoded response.
147 open_vcdiff::HashedDictionary vcdiff_dictionary(
148 kDictionaryContents, strlen(kDictionaryContents));
149 bool result = vcdiff_dictionary.Init();
150 DCHECK(result);
151 open_vcdiff::VCDiffStreamingEncoder encoder(&vcdiff_dictionary, 0, false);
152 encoded_data_ = dictionary_server_hash_;
153 encoded_data_ += '\0';
154 result = encoder.StartEncoding(&encoded_data_);
155 DCHECK(result);
156 result = encoder.EncodeChunk(
157 kSampleData, strlen(kSampleData), &encoded_data_);
158 DCHECK(result);
159 result = encoder.FinishEncoding(&encoded_data_);
160 DCHECK(result);
161 }
162
163 static bool ClientIsAdvertisingSdchEncoding(const HttpRequestHeaderMap& map) {
164 std::string value;
165 if (!GetRequestHeader(map, "accept-encoding", &value))
166 return false;
167 base::StringTokenizer tokenizer(value, " ,");
168 while (tokenizer.GetNext()) {
169 if (base::strcasecmp(tokenizer.token().c_str(), "sdch"))
170 return true;
171 }
172 return false;
173 }
174
175 bool ShouldRespondWithSdchEncoding(const HttpRequestHeaderMap& map) {
176 std::string value;
177 if (!GetRequestHeader(map, "avail-dictionary", &value))
178 return false;
179 return value == dictionary_client_hash_;
180 }
181
182 scoped_ptr<net::test_server::HttpResponse> HandleRequest(
183 const net::test_server::HttpRequest& request) {
184 request_vector_.push_back(request);
185
186 scoped_ptr<net::test_server::BasicHttpResponse> response(
187 new net::test_server::BasicHttpResponse);
188 if (request.relative_url == kDataURLPath) {
189 if (ShouldRespondWithSdchEncoding(request.headers)) {
190 // Note that chrome doesn't advertise accepting SDCH encoding
191 // for POSTs (because the meta-refresh hack would break a POST),
192 // but that's not for the server to enforce.
193 DCHECK_NE(encoded_data_, "");
194 response->set_content_type("text/html");
195 response->set_content(encoded_data_);
196 response->AddCustomHeader("Content-Encoding", "sdch");
197 // We allow tests to set caching on the sdch response,
198 // so that we can force an encoded response with no
199 // dictionary.
200 if (cache_sdch_response_)
201 response->AddCustomHeader("Cache-Control", "max-age=3600");
202 else
203 response->AddCustomHeader("Cache-Control", "no-store");
204 } else {
205 response->set_content_type("text/plain");
206 response->set_content(kSampleData);
207 if (ClientIsAdvertisingSdchEncoding(request.headers))
208 response->AddCustomHeader("Get-Dictionary", kDictionaryURLPath);
209 // We never cache the plain data response, to make it
210 // easy to refresh after we get the dictionary.
211 response->AddCustomHeader("Cache-Control", "no-store");
212 }
213 } else {
214 DCHECK_EQ(request.relative_url, kDictionaryURLPath);
215 DCHECK_NE(sdch_dictionary_contents_, "");
216 response->set_content_type("application/x-sdch-dictionary");
217 response->set_content(sdch_dictionary_contents_);
218 }
219 std::vector<base::Closure> callbacks;
220 callbacks.swap(callback_vector_);
221 for (std::vector<base::Closure>::iterator it = callbacks.begin();
222 it != callbacks.end(); ++it) {
223 it->Run();
224 }
225 return response.PassAs<net::test_server::HttpResponse>();
226 }
227
228 void WaitAndGetRequestVector(int num_requests,
229 base::Closure callback,
230 RequestVector* v) {
231 DCHECK_LT(0, num_requests);
232 if (static_cast<size_t>(num_requests) > request_vector_.size()) {
233 callback_vector_.push_back(
234 base::Bind(&SdchResponseHandler::WaitAndGetRequestVector,
235 weak_ptr_factory_.GetWeakPtr(), num_requests,
236 callback, v));
237 return;
238 }
239 *v = request_vector_;
240 content::BrowserThread::PostTask(
241 content::BrowserThread::UI, FROM_HERE, callback);
242 }
243
244 void set_cache_sdch_response(bool cache_sdch_response) {
245 cache_sdch_response_ = cache_sdch_response;
246 }
247
248 private:
249 bool cache_sdch_response_;
250 std::string encoded_data_;
251 std::string sdch_dictionary_contents_;
252 std::string dictionary_client_hash_;
253 std::string dictionary_server_hash_;
254 RequestVector request_vector_;
255 std::vector<base::Closure> callback_vector_;
256 base::WeakPtrFactory<SdchResponseHandler> weak_ptr_factory_;
257 };
258
259 class SdchBrowserTest : public InProcessBrowserTest, net::URLFetcherDelegate {
260 public:
261 static const char kTestHost[];
262
263 SdchBrowserTest()
264 : response_handler_(kTestHost),
265 url_request_context_getter_(NULL),
266 url_fetch_complete_(false),
267 waiting_(false) {}
268
269 // Helper functions for fetching data.
270
271 void FetchUrlDetailed(GURL url, net::URLRequestContextGetter* getter) {
272 url_fetch_complete_ = false;
273 fetcher_.reset(net::URLFetcher::Create(url, net::URLFetcher::GET, this));
274 fetcher_->SetRequestContext(getter);
275 fetcher_->Start();
276 if (!url_fetch_complete_) {
277 waiting_ = true;
278 content::RunMessageLoop();
279 waiting_ = false;
280 }
281 CHECK(url_fetch_complete_);
282 }
283
284 void FetchUrl(GURL url) {
285 FetchUrlDetailed(url, url_request_context_getter_);
286 }
287
288 const net::URLRequestStatus& fetcher_status() const {
289 return fetcher_->GetStatus();
290 }
291
292 int fetcher_response_code() const {
293 return (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS ?
294 fetcher_->GetResponseCode() : 0);
295 }
296
297 const net::HttpResponseHeaders* fetcher_response_headers() const {
298 return (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS ?
299 fetcher_->GetResponseHeaders() : NULL);
300 }
301
302 std::string fetcher_response_contents() const {
303 std::string contents;
304 if (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS)
305 CHECK(fetcher_->GetResponseAsString(&contents));
306 return contents;
307 }
308
309 // Get the data from the server. Return value is success/failure of the
310 // data operation, |*sdch_encoding_used| indicates whether or not the
311 // data was retrieved with sdch encoding.
312 // This is done through FetchUrl(), so the various helper functions
313 // will have valid status if it returns successfully.
314 bool GetDataDetailed(net::URLRequestContextGetter* getter,
315 bool* sdch_encoding_used) {
316 FetchUrlDetailed(
317 GURL(base::StringPrintf(
318 "http://%s:%d%s", kTestHost, test_server_port(), kDataURLPath)),
319 getter);
320 EXPECT_EQ(net::URLRequestStatus::SUCCESS, fetcher_status().status())
321 << "Error code is " << fetcher_status().error();
322 EXPECT_EQ(200, fetcher_response_code());
323 EXPECT_EQ(kSampleData, fetcher_response_contents());
324
325 if (net::URLRequestStatus::SUCCESS != fetcher_status().status() ||
326 200 != fetcher_response_code()) {
327 *sdch_encoding_used = false;
328 return false;
329 }
330
331 *sdch_encoding_used =
332 fetcher_response_headers()->HasHeaderValue("Content-Encoding", "sdch");
333
334 if (fetcher_response_contents() != kSampleData)
335 return false;
336
337 return true;
338 }
339
340 bool GetData(bool* sdch_encoding_used) {
341 return GetDataDetailed(
342 url_request_context_getter_, sdch_encoding_used);
343 }
344
345 // Client information and control.
346
347 int GetNumberOfDictionaryFetches(Profile* profile) {
348 int fetches = -1;
349 base::RunLoop run_loop;
350 content::BrowserThread::PostTaskAndReply(
351 content::BrowserThread::IO, FROM_HERE,
352 base::Bind(&SdchBrowserTest::GetNumberOfDictionaryFetchesOnIOThread,
353 base::Unretained(profile->GetRequestContext()),
354 &fetches),
355 run_loop.QuitClosure());
356 run_loop.Run();
357 DCHECK_NE(-1, fetches);
358 return fetches;
359 }
360
361 void BrowsingDataRemoveAndWait(int remove_mask) {
362 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
363 browser()->profile(), BrowsingDataRemover::LAST_HOUR);
364 BrowsingDataRemoverCompletionObserver completion_observer(remover);
365 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
366 completion_observer.BlockUntilCompletion();
367 }
368
369 // Something of a cheat; nuke the dictionaries off the SdchManager without
370 // touching the cache (which browsing data remover would do).
371 void NukeSdchDictionaries() {
372 base::RunLoop run_loop;
373 content::BrowserThread::PostTaskAndReply(
374 content::BrowserThread::IO, FROM_HERE,
375 base::Bind(&SdchBrowserTest::NukeSdchDictionariesOnIOThread,
376 url_request_context_getter_),
377 run_loop.QuitClosure());
378 run_loop.Run();
379 }
380
381 // Create a second browser based on a second profile to work within
382 // multi-profile.
383 bool SetupSecondBrowser() {
384 base::FilePath user_data_dir;
385 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
386
387 if (!second_profile_data_dir_.CreateUniqueTempDirUnderPath(user_data_dir))
388 return false;
389
390 second_profile_ = g_browser_process->profile_manager()->GetProfile(
391 second_profile_data_dir_.path());
392 if (!second_profile_) return false;
393
394 second_browser_ = new Browser(Browser::CreateParams(
395 second_profile_, browser()->host_desktop_type()));
396 if (!second_browser_) return false;
397
398 chrome::AddSelectedTabWithURL(second_browser_,
399 GURL(url::kAboutBlankURL),
400 content::PAGE_TRANSITION_AUTO_TOPLEVEL);
401 content::WaitForLoadStop(
402 second_browser_->tab_strip_model()->GetActiveWebContents());
403 second_browser_->window()->Show();
404
405 return true;
406 }
407
408 Browser* second_browser() { return second_browser_; }
409
410 // Server information and control.
411
412 void WaitAndGetTestVector(int num_requests, RequestVector* result) {
413 base::RunLoop run_loop;
414 content::BrowserThread::PostTask(
415 content::BrowserThread::IO, FROM_HERE,
416 base::Bind(&SdchResponseHandler::WaitAndGetRequestVector,
417 base::Unretained(&response_handler_),
418 num_requests,
419 run_loop.QuitClosure(),
420 result));
421 run_loop.Run();
422 }
423
424 int test_server_port() { return test_server_.port(); }
425
426 void SetSdchCacheability(bool cache_sdch_response) {
427 base::RunLoop run_loop;
428 content::BrowserThread::PostTaskAndReply(
429 content::BrowserThread::IO, FROM_HERE,
430 base::Bind(&SdchResponseHandler::set_cache_sdch_response,
431 base::Unretained(&response_handler_),
432 cache_sdch_response),
433 run_loop.QuitClosure());
434 run_loop.Run();
435 }
436
437 // Helper function for common test pattern.
438 //
439 // This function gets the data, confirms that the initial sending of the
440 // data included a dictionary advertisement, that that advertisement
441 // resulted in queueing a dictionary fetch, forces that fetch to
442 // go through, and confirms that a follow-on data load uses SDCH
443 // encoding. Returns true if the entire sequence of events occurred.
444 bool ForceSdchDictionaryLoad(Browser* browser) {
445 bool sdch_encoding_used = true;
446 bool data_gotten = GetDataDetailed(
447 browser->profile()->GetRequestContext(), &sdch_encoding_used);
448 EXPECT_TRUE(data_gotten);
449 if (!data_gotten) return false;
450 EXPECT_FALSE(sdch_encoding_used);
451
452 // Confirm that we were told to get the dictionary
453 const net::HttpResponseHeaders* headers = fetcher_response_headers();
454 std::string value;
455 bool have_dict_header =
456 headers->EnumerateHeader(NULL, "Get-Dictionary", &value);
457 EXPECT_TRUE(have_dict_header);
458 if (!have_dict_header) return false;
459
460 // If the above didn't result in a dictionary fetch being queued, the
461 // rest of the test will time out. Avoid that.
462 int num_fetches = GetNumberOfDictionaryFetches(browser->profile());
463 EXPECT_EQ(1, num_fetches);
464 if (1 != num_fetches) return false;
465
466 // Wait until the dictionary fetch actually happens.
467 RequestVector request_vector;
468 WaitAndGetTestVector(2, &request_vector);
469 EXPECT_EQ(request_vector[1].relative_url, kDictionaryURLPath);
470 if (request_vector[1].relative_url != kDictionaryURLPath) return false;
471
472 // Do a round trip to the server ignoring the encoding, presuming
473 // that if we've gotten data to this thread, the dictionary's made
474 // it into the SdchManager.
475 data_gotten = GetDataDetailed(
476 browser->profile()->GetRequestContext(), &sdch_encoding_used);
477 EXPECT_TRUE(data_gotten);
478 if (!data_gotten) return false;
479
480 // Now data fetches should be SDCH encoded.
481 sdch_encoding_used = false;
482 data_gotten = GetDataDetailed(
483 browser->profile()->GetRequestContext(), &sdch_encoding_used);
484 EXPECT_TRUE(data_gotten);
485 EXPECT_TRUE(sdch_encoding_used);
486
487 if (!data_gotten || !sdch_encoding_used) return false;
488
489 // Confirm the request vector looks at this point as expected.
490 WaitAndGetTestVector(4, &request_vector);
491 EXPECT_EQ(4u, request_vector.size());
492 EXPECT_EQ(request_vector[2].relative_url, kDataURLPath);
493 EXPECT_EQ(request_vector[3].relative_url, kDataURLPath);
494 return (4u == request_vector.size() &&
495 request_vector[2].relative_url == kDataURLPath &&
496 request_vector[3].relative_url == kDataURLPath);
497 }
498
499 private:
500 static void NukeSdchDictionariesOnIOThread(
501 net::URLRequestContextGetter* context_getter) {
502 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
503 net::SdchManager* sdch_manager =
504 context_getter->GetURLRequestContext()->sdch_manager();
505 DCHECK(sdch_manager);
506 sdch_manager->ClearData();
507 }
508
509 static void GetNumberOfDictionaryFetchesOnIOThread(
510 net::URLRequestContextGetter* url_request_context_getter,
511 int* result) {
512 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
513 net::SdchManager* sdch_manager =
514 url_request_context_getter->GetURLRequestContext()->sdch_manager();
515 DCHECK(sdch_manager);
516 *result = sdch_manager->GetFetchesCountForTesting();
517 }
518
519 // InProcessBrowserTest
520 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE {
521 command_line->AppendSwitchASCII(
522 switches::kHostResolverRules,
523 "MAP " + std::string(kTestHost) + " 127.0.0.1");
524 }
525
526 virtual void SetUpOnMainThread() OVERRIDE {
527 test_server_.RegisterRequestHandler(
528 base::Bind(&SdchResponseHandler::HandleRequest,
529 base::Unretained(&response_handler_)));
530 CHECK(test_server_.InitializeAndWaitUntilReady());
531 url_request_context_getter_ = browser()->profile()->GetRequestContext();
532 }
533
534 virtual void TearDownOnMainThread() OVERRIDE {
535 CHECK(test_server_.ShutdownAndWaitUntilComplete());
536 }
537
538 // URLFetcherDelegate
539 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE {
540 url_fetch_complete_ = true;
541 if (waiting_)
542 base::MessageLoopForUI::current()->Quit();
543 }
544
545 SdchResponseHandler response_handler_;
546 net::test_server::EmbeddedTestServer test_server_;
547 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
548 scoped_ptr<net::URLFetcher> fetcher_;
549 bool url_fetch_complete_;
550 bool waiting_;
551 base::ScopedTempDir second_profile_data_dir_;
552 Profile* second_profile_;
553 Browser* second_browser_;
554 };
555
556 const char SdchBrowserTest::kTestHost[] = "our.test.host.com";
557
558 // Confirm that after getting a dictionary, calling the browsing
559 // data remover renders it unusable. Also (in calling
560 // ForceSdchDictionaryLoad()) servers as a smoke test for SDCH.
561 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, BrowsingDataRemover) {
562 ASSERT_TRUE(ForceSdchDictionaryLoad(browser()));
563
564 // Confirm browsing data remover without removing the cache leaves
565 // SDCH alone.
566 BrowsingDataRemoveAndWait(BrowsingDataRemover::REMOVE_ALL &
567 ~BrowsingDataRemover::REMOVE_CACHE);
568 bool sdch_encoding_used = false;
569 ASSERT_TRUE(GetData(&sdch_encoding_used));
570 EXPECT_TRUE(sdch_encoding_used);
571
572 // Confirm browsing data remover removing the cache clears SDCH state.
573 BrowsingDataRemoveAndWait(BrowsingDataRemover::REMOVE_CACHE);
574 sdch_encoding_used = false;
575 ASSERT_TRUE(GetData(&sdch_encoding_used));
576 EXPECT_FALSE(sdch_encoding_used);
577 }
578
579 // Confirm dictionaries not visible in other profiles.
580 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, Isolation) {
581 ASSERT_TRUE(ForceSdchDictionaryLoad(browser()));
582 ASSERT_TRUE(SetupSecondBrowser());
583
584 // Data fetches from incognito or separate profiles should not be SDCH
585 // encoded.
586 bool sdch_encoding_used = true;
587 Browser* incognito_browser = CreateIncognitoBrowser();
588 EXPECT_TRUE(GetDataDetailed(
589 incognito_browser->profile()->GetRequestContext(),
590 &sdch_encoding_used));
591 EXPECT_FALSE(sdch_encoding_used);
592
593 sdch_encoding_used = true;
594 EXPECT_TRUE(GetDataDetailed(
595 second_browser()->profile()->GetRequestContext(), &sdch_encoding_used));
596 EXPECT_FALSE(sdch_encoding_used);
597 }
598
599 // Confirm a dictionary loaded in incognito isn't visible in the main profile.
600 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, ReverseIsolation) {
601 Browser* incognito_browser = CreateIncognitoBrowser();
602 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser));
603
604 // Data fetches on main browser should not be SDCH encoded.
605 bool sdch_encoding_used = true;
606 ASSERT_TRUE(GetData(&sdch_encoding_used));
607 EXPECT_FALSE(sdch_encoding_used);
608 }
609
610 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698