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

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: Sync'd to r288030. 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 if (!base::strcasecmp(it->first.c_str(), header)) {
107 *value = it->second;
108 return true;
109 }
110 }
111 return false;
112 }
113
114 // Do a URL-safe base64 encoding. See the SDCH spec "Dictionary Identifier"
115 // section, and RFC 3548 section 4.
116 void SafeBase64Encode(const std::string& input_value, std::string* output) {
117 DCHECK(output);
118 base::Base64Encode(input_value, output);
119 std::replace(output->begin(), output->end(), '+', '-');
120 std::replace(output->begin(), output->end(), '/', '_');
121 }
122
123 // Class that bundles responses for an EmbeddedTestServer().
124 // Dictionary is at <domain>/dict, data at <domain>/data.
125 // The data is sent SDCH encoded if that's allowed by protoocol.
126 class SdchResponseHandler {
127 public:
128 // Do initial preparation so that SDCH requests can be handled.
129 explicit SdchResponseHandler(std::string domain)
130 : cache_sdch_response_(false),
131 weak_ptr_factory_(this) {
132 // Dictionary
133 sdch_dictionary_contents_ = "Domain: ";
134 sdch_dictionary_contents_ += domain;
135 sdch_dictionary_contents_ += "\n\n";
136 sdch_dictionary_contents_ += kDictionaryContents;
137
138 // Dictionary hash for client and server.
139 char binary_hash[32];
140 crypto::SHA256HashString(sdch_dictionary_contents_, binary_hash,
141 sizeof(binary_hash));
142 SafeBase64Encode(std::string(&binary_hash[0], 6), &dictionary_client_hash_);
143 SafeBase64Encode(std::string(&binary_hash[6], 6), &dictionary_server_hash_);
144
145 // Encoded response.
146 open_vcdiff::HashedDictionary vcdiff_dictionary(
147 kDictionaryContents, strlen(kDictionaryContents));
148 bool result = vcdiff_dictionary.Init();
149 DCHECK(result);
150 open_vcdiff::VCDiffStreamingEncoder encoder(&vcdiff_dictionary, 0, false);
151 encoded_data_ = dictionary_server_hash_;
152 encoded_data_ += '\0';
153 result = encoder.StartEncoding(&encoded_data_);
154 DCHECK(result);
155 result = encoder.EncodeChunk(
156 kSampleData, strlen(kSampleData), &encoded_data_);
157 DCHECK(result);
158 result = encoder.FinishEncoding(&encoded_data_);
159 DCHECK(result);
160 }
161
162 static bool ClientIsAdvertisingSdchEncoding(const HttpRequestHeaderMap& map) {
163 std::string value;
164 if (!GetRequestHeader(map, "accept-encoding", &value))
165 return false;
166 base::StringTokenizer tokenizer(value, " ,");
167 while (tokenizer.GetNext()) {
168 if (base::strcasecmp(tokenizer.token().c_str(), "sdch"))
169 return true;
170 }
171 return false;
172 }
173
174 bool ShouldRespondWithSdchEncoding(const HttpRequestHeaderMap& map) {
175 std::string value;
176 if (!GetRequestHeader(map, "avail-dictionary", &value))
177 return false;
178 return value == dictionary_client_hash_;
179 }
180
181 scoped_ptr<net::test_server::HttpResponse> HandleRequest(
182 const net::test_server::HttpRequest& request) {
183 request_vector_.push_back(request);
184
185 scoped_ptr<net::test_server::BasicHttpResponse> response(
186 new net::test_server::BasicHttpResponse);
187 if (request.relative_url == kDataURLPath) {
188 if (ShouldRespondWithSdchEncoding(request.headers)) {
189 // Note that chrome doesn't advertise accepting SDCH encoding
190 // for POSTs (because the meta-refresh hack would break a POST),
191 // but that's not for the server to enforce.
192 DCHECK_NE(encoded_data_, "");
193 response->set_content_type("text/html");
194 response->set_content(encoded_data_);
195 response->AddCustomHeader("Content-Encoding", "sdch");
196 // We allow tests to set caching on the sdch response,
197 // so that we can force an encoded response with no
198 // dictionary.
199 if (cache_sdch_response_)
200 response->AddCustomHeader("Cache-Control", "max-age=3600");
201 else
202 response->AddCustomHeader("Cache-Control", "no-store");
203 } else {
204 response->set_content_type("text/plain");
205 response->set_content(kSampleData);
206 if (ClientIsAdvertisingSdchEncoding(request.headers))
207 response->AddCustomHeader("Get-Dictionary", kDictionaryURLPath);
208 // We never cache the plain data response, to make it
209 // easy to refresh after we get the dictionary.
210 response->AddCustomHeader("Cache-Control", "no-store");
211 }
212 } else {
213 DCHECK_EQ(request.relative_url, kDictionaryURLPath);
214 DCHECK_NE(sdch_dictionary_contents_, "");
215 response->set_content_type("application/x-sdch-dictionary");
216 response->set_content(sdch_dictionary_contents_);
217 }
218 std::vector<base::Closure> callbacks;
219 callbacks.swap(callback_vector_);
220 for (std::vector<base::Closure>::iterator it = callbacks.begin();
221 it != callbacks.end(); ++it) {
222 it->Run();
223 }
224 return response.PassAs<net::test_server::HttpResponse>();
225 }
226
227 void WaitAndGetRequestVector(int num_requests,
228 base::Closure callback,
229 RequestVector* v) {
230 DCHECK_LT(0, num_requests);
231 if (static_cast<size_t>(num_requests) > request_vector_.size()) {
232 callback_vector_.push_back(
233 base::Bind(&SdchResponseHandler::WaitAndGetRequestVector,
234 weak_ptr_factory_.GetWeakPtr(), num_requests,
235 callback, v));
236 return;
237 }
238 *v = request_vector_;
239 content::BrowserThread::PostTask(
240 content::BrowserThread::UI, FROM_HERE, callback);
241 }
242
243 void set_cache_sdch_response(bool cache_sdch_response) {
244 cache_sdch_response_ = cache_sdch_response;
245 }
246
247 private:
248 bool cache_sdch_response_;
249 std::string encoded_data_;
250 std::string sdch_dictionary_contents_;
251 std::string dictionary_client_hash_;
252 std::string dictionary_server_hash_;
253 RequestVector request_vector_;
254 std::vector<base::Closure> callback_vector_;
255 base::WeakPtrFactory<SdchResponseHandler> weak_ptr_factory_;
256 };
257
258 class SdchBrowserTest : public InProcessBrowserTest, net::URLFetcherDelegate {
259 public:
260 static const char kTestHost[];
261
262 SdchBrowserTest()
263 : response_handler_(kTestHost),
264 url_request_context_getter_(NULL),
265 url_fetch_complete_(false),
266 waiting_(false) {}
267
268 // Helper functions for fetching data.
269
270 void FetchUrlDetailed(GURL url, net::URLRequestContextGetter* getter) {
271 url_fetch_complete_ = false;
272 fetcher_.reset(net::URLFetcher::Create(url, net::URLFetcher::GET, this));
273 fetcher_->SetRequestContext(getter);
274 fetcher_->Start();
275 if (!url_fetch_complete_) {
276 waiting_ = true;
277 content::RunMessageLoop();
278 waiting_ = false;
279 }
280 CHECK(url_fetch_complete_);
281 }
282
283 void FetchUrl(GURL url) {
284 FetchUrlDetailed(url, url_request_context_getter_);
285 }
286
287 const net::URLRequestStatus& fetcher_status() const {
288 return fetcher_->GetStatus();
289 }
290
291 int fetcher_response_code() const {
jar (doing other things) 2014/08/13 01:28:58 nit: please use bouncy caps, instead of hacker sty
Randy Smith (Not in Mondays) 2014/08/13 02:05:25 No argument at all; sorry they looked like this.
292 return (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS ?
293 fetcher_->GetResponseCode() : 0);
294 }
295
296 const net::HttpResponseHeaders* fetcher_response_headers() const {
297 return (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS ?
298 fetcher_->GetResponseHeaders() : NULL);
299 }
300
301 std::string fetcher_response_contents() const {
302 std::string contents;
303 if (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS)
304 CHECK(fetcher_->GetResponseAsString(&contents));
305 return contents;
306 }
307
308 // Get the data from the server. Return value is success/failure of the
309 // data operation, |*sdch_encoding_used| indicates whether or not the
310 // data was retrieved with sdch encoding.
311 // This is done through FetchUrl(), so the various helper functions
312 // will have valid status if it returns successfully.
313 bool GetDataDetailed(net::URLRequestContextGetter* getter,
314 bool* sdch_encoding_used) {
315 FetchUrlDetailed(
316 GURL(base::StringPrintf(
317 "http://%s:%d%s", kTestHost, test_server_port(), kDataURLPath)),
318 getter);
319 EXPECT_EQ(net::URLRequestStatus::SUCCESS, fetcher_status().status())
320 << "Error code is " << fetcher_status().error();
321 EXPECT_EQ(200, fetcher_response_code());
322 EXPECT_EQ(kSampleData, fetcher_response_contents());
323
324 if (net::URLRequestStatus::SUCCESS != fetcher_status().status() ||
325 200 != fetcher_response_code()) {
326 *sdch_encoding_used = false;
327 return false;
328 }
329
330 *sdch_encoding_used =
331 fetcher_response_headers()->HasHeaderValue("Content-Encoding", "sdch");
332
333 if (fetcher_response_contents() != kSampleData)
334 return false;
335
336 return true;
337 }
338
339 bool GetData(bool* sdch_encoding_used) {
340 return GetDataDetailed(
341 url_request_context_getter_, sdch_encoding_used);
342 }
343
344 // Client information and control.
345
346 int GetNumberOfDictionaryFetches(Profile* profile) {
347 int fetches = -1;
348 base::RunLoop run_loop;
349 content::BrowserThread::PostTaskAndReply(
350 content::BrowserThread::IO, FROM_HERE,
351 base::Bind(&SdchBrowserTest::GetNumberOfDictionaryFetchesOnIOThread,
352 base::Unretained(profile->GetRequestContext()),
353 &fetches),
354 run_loop.QuitClosure());
355 run_loop.Run();
356 DCHECK_NE(-1, fetches);
357 return fetches;
358 }
359
360 void BrowsingDataRemoveAndWait(int remove_mask) {
361 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
362 browser()->profile(), BrowsingDataRemover::LAST_HOUR);
363 BrowsingDataRemoverCompletionObserver completion_observer(remover);
364 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
365 completion_observer.BlockUntilCompletion();
366 }
367
368 // Something of a cheat; nuke the dictionaries off the SdchManager without
369 // touching the cache (which browsing data remover would do).
370 void NukeSdchDictionaries() {
371 base::RunLoop run_loop;
372 content::BrowserThread::PostTaskAndReply(
373 content::BrowserThread::IO, FROM_HERE,
374 base::Bind(&SdchBrowserTest::NukeSdchDictionariesOnIOThread,
375 url_request_context_getter_),
376 run_loop.QuitClosure());
377 run_loop.Run();
378 }
379
380 // Create a second browser based on a second profile to work within
381 // multi-profile.
382 bool SetupSecondBrowser() {
383 base::FilePath user_data_dir;
384 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
385
386 if (!second_profile_data_dir_.CreateUniqueTempDirUnderPath(user_data_dir))
387 return false;
388
389 second_profile_ = g_browser_process->profile_manager()->GetProfile(
390 second_profile_data_dir_.path());
391 if (!second_profile_) return false;
392
393 second_browser_ = new Browser(Browser::CreateParams(
394 second_profile_, browser()->host_desktop_type()));
395 if (!second_browser_) return false;
396
397 chrome::AddSelectedTabWithURL(second_browser_,
398 GURL(url::kAboutBlankURL),
399 content::PAGE_TRANSITION_AUTO_TOPLEVEL);
400 content::WaitForLoadStop(
401 second_browser_->tab_strip_model()->GetActiveWebContents());
402 second_browser_->window()->Show();
403
404 return true;
405 }
406
407 Browser* second_browser() { return second_browser_; }
408
409 // Server information and control.
410
411 void WaitAndGetTestVector(int num_requests, RequestVector* result) {
412 base::RunLoop run_loop;
413 content::BrowserThread::PostTask(
414 content::BrowserThread::IO, FROM_HERE,
415 base::Bind(&SdchResponseHandler::WaitAndGetRequestVector,
416 base::Unretained(&response_handler_),
417 num_requests,
418 run_loop.QuitClosure(),
419 result));
420 run_loop.Run();
421 }
422
423 int test_server_port() { return test_server_.port(); }
424
425 void SetSdchCacheability(bool cache_sdch_response) {
426 base::RunLoop run_loop;
427 content::BrowserThread::PostTaskAndReply(
428 content::BrowserThread::IO, FROM_HERE,
429 base::Bind(&SdchResponseHandler::set_cache_sdch_response,
430 base::Unretained(&response_handler_),
431 cache_sdch_response),
432 run_loop.QuitClosure());
433 run_loop.Run();
434 }
435
436 // Helper function for common test pattern.
437 //
438 // This function gets the data, confirms that the initial sending of the
439 // data included a dictionary advertisement, that that advertisement
440 // resulted in queueing a dictionary fetch, forces that fetch to
441 // go through, and confirms that a follow-on data load uses SDCH
442 // encoding. Returns true if the entire sequence of events occurred.
443 bool ForceSdchDictionaryLoad(Browser* browser) {
444 bool sdch_encoding_used = true;
445 bool data_gotten = GetDataDetailed(
446 browser->profile()->GetRequestContext(), &sdch_encoding_used);
447 EXPECT_TRUE(data_gotten);
448 if (!data_gotten) return false;
449 EXPECT_FALSE(sdch_encoding_used);
450
451 // Confirm that we were told to get the dictionary
452 const net::HttpResponseHeaders* headers = fetcher_response_headers();
453 std::string value;
454 bool have_dict_header =
455 headers->EnumerateHeader(NULL, "Get-Dictionary", &value);
456 EXPECT_TRUE(have_dict_header);
457 if (!have_dict_header) return false;
458
459 // If the above didn't result in a dictionary fetch being queued, the
460 // rest of the test will time out. Avoid that.
461 int num_fetches = GetNumberOfDictionaryFetches(browser->profile());
462 EXPECT_EQ(1, num_fetches);
463 if (1 != num_fetches) return false;
464
465 // Wait until the dictionary fetch actually happens.
466 RequestVector request_vector;
467 WaitAndGetTestVector(2, &request_vector);
468 EXPECT_EQ(request_vector[1].relative_url, kDictionaryURLPath);
469 if (request_vector[1].relative_url != kDictionaryURLPath) return false;
470
471 // Do a round trip to the server ignoring the encoding, presuming
472 // that if we've gotten data to this thread, the dictionary's made
473 // it into the SdchManager.
474 data_gotten = GetDataDetailed(
475 browser->profile()->GetRequestContext(), &sdch_encoding_used);
476 EXPECT_TRUE(data_gotten);
477 if (!data_gotten) return false;
478
479 // Now data fetches should be SDCH encoded.
480 sdch_encoding_used = false;
481 data_gotten = GetDataDetailed(
482 browser->profile()->GetRequestContext(), &sdch_encoding_used);
483 EXPECT_TRUE(data_gotten);
484 EXPECT_TRUE(sdch_encoding_used);
485
486 if (!data_gotten || !sdch_encoding_used) return false;
487
488 // Confirm the request vector looks at this point as expected.
489 WaitAndGetTestVector(4, &request_vector);
490 EXPECT_EQ(4u, request_vector.size());
491 EXPECT_EQ(request_vector[2].relative_url, kDataURLPath);
492 EXPECT_EQ(request_vector[3].relative_url, kDataURLPath);
493 return (4u == request_vector.size() &&
494 request_vector[2].relative_url == kDataURLPath &&
495 request_vector[3].relative_url == kDataURLPath);
496 }
497
498 private:
499 static void NukeSdchDictionariesOnIOThread(
500 net::URLRequestContextGetter* context_getter) {
501 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
502 net::SdchManager* sdch_manager =
503 context_getter->GetURLRequestContext()->sdch_manager();
504 DCHECK(sdch_manager);
505 sdch_manager->ClearData();
506 }
507
508 static void GetNumberOfDictionaryFetchesOnIOThread(
509 net::URLRequestContextGetter* url_request_context_getter,
510 int* result) {
511 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
512 net::SdchManager* sdch_manager =
513 url_request_context_getter->GetURLRequestContext()->sdch_manager();
514 DCHECK(sdch_manager);
515 *result = sdch_manager->GetFetchesCountForTesting();
516 }
517
518 // InProcessBrowserTest
519 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE {
520 command_line->AppendSwitchASCII(
521 switches::kHostResolverRules,
522 "MAP " + std::string(kTestHost) + " 127.0.0.1");
523 }
524
525 virtual void SetUpOnMainThread() OVERRIDE {
526 test_server_.RegisterRequestHandler(
527 base::Bind(&SdchResponseHandler::HandleRequest,
528 base::Unretained(&response_handler_)));
529 CHECK(test_server_.InitializeAndWaitUntilReady());
530 url_request_context_getter_ = browser()->profile()->GetRequestContext();
531 }
532
533 virtual void TearDownOnMainThread() OVERRIDE {
534 CHECK(test_server_.ShutdownAndWaitUntilComplete());
535 }
536
537 // URLFetcherDelegate
538 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE {
539 url_fetch_complete_ = true;
540 if (waiting_)
541 base::MessageLoopForUI::current()->Quit();
542 }
543
544 SdchResponseHandler response_handler_;
545 net::test_server::EmbeddedTestServer test_server_;
546 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
547 scoped_ptr<net::URLFetcher> fetcher_;
548 bool url_fetch_complete_;
549 bool waiting_;
550 base::ScopedTempDir second_profile_data_dir_;
551 Profile* second_profile_;
552 Browser* second_browser_;
553 };
554
555 const char SdchBrowserTest::kTestHost[] = "our.test.host.com";
556
557 // Confirm that after getting a dictionary, calling the browsing
558 // data remover renders it unusable. Also (in calling
559 // ForceSdchDictionaryLoad()) servers as a smoke test for SDCH.
560 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, BrowsingDataRemover) {
561 ASSERT_TRUE(ForceSdchDictionaryLoad(browser()));
562
563 // Confirm browsing data remover without removing the cache leaves
564 // SDCH alone.
565 BrowsingDataRemoveAndWait(BrowsingDataRemover::REMOVE_ALL &
566 ~BrowsingDataRemover::REMOVE_CACHE);
567 bool sdch_encoding_used = false;
568 ASSERT_TRUE(GetData(&sdch_encoding_used));
569 EXPECT_TRUE(sdch_encoding_used);
570
571 // Confirm browsing data remover removing the cache clears SDCH state.
572 BrowsingDataRemoveAndWait(BrowsingDataRemover::REMOVE_CACHE);
573 sdch_encoding_used = false;
574 ASSERT_TRUE(GetData(&sdch_encoding_used));
575 EXPECT_FALSE(sdch_encoding_used);
576 }
577
578 // Confirm dictionaries not visible in other profiles.
579 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, Isolation) {
580 ASSERT_TRUE(ForceSdchDictionaryLoad(browser()));
581 ASSERT_TRUE(SetupSecondBrowser());
582
583 // Data fetches from incognito or separate profiles should not be SDCH
584 // encoded.
585 bool sdch_encoding_used = true;
586 Browser* incognito_browser = CreateIncognitoBrowser();
587 EXPECT_TRUE(GetDataDetailed(
588 incognito_browser->profile()->GetRequestContext(),
589 &sdch_encoding_used));
590 EXPECT_FALSE(sdch_encoding_used);
591
592 sdch_encoding_used = true;
593 EXPECT_TRUE(GetDataDetailed(
594 second_browser()->profile()->GetRequestContext(), &sdch_encoding_used));
595 EXPECT_FALSE(sdch_encoding_used);
596 }
597
598 // Confirm a dictionary loaded in incognito isn't visible in the main profile.
599 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, ReverseIsolation) {
600 Browser* incognito_browser = CreateIncognitoBrowser();
601 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser));
602
603 // Data fetches on main browser should not be SDCH encoded.
604 bool sdch_encoding_used = true;
605 ASSERT_TRUE(GetData(&sdch_encoding_used));
606 EXPECT_FALSE(sdch_encoding_used);
607 }
608
609 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698