| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 // End-to-end SDCH tests.  Uses the embedded test server to return SDCH | 5 // End-to-end SDCH tests.  Uses the embedded test server to return SDCH | 
| 6 // results | 6 // results | 
| 7 | 7 | 
| 8 #include <stddef.h> | 8 #include <stddef.h> | 
| 9 #include <stdint.h> | 9 #include <stdint.h> | 
| 10 #include <utility> | 10 #include <utility> | 
| 11 | 11 | 
| 12 #include "base/base64.h" | 12 #include "base/base64.h" | 
| 13 #include "base/bind.h" | 13 #include "base/bind.h" | 
| 14 #include "base/callback.h" | 14 #include "base/callback.h" | 
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" | 
| 16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" | 
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" | 
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" | 
| 19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" | 
| 20 #include "base/strings/string_tokenizer.h" | 20 #include "base/strings/string_tokenizer.h" | 
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" | 
| 22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" | 
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" | 
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" | 
| 25 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 25 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 
| 26 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 26 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 
| 27 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 27 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 
| 28 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 28 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 
|  | 29 #include "chrome/browser/browsing_data/chrome_browsing_data_types.h" | 
| 29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" | 
| 30 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" | 
| 31 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" | 
| 32 #include "chrome/browser/ui/browser_tabstrip.h" | 33 #include "chrome/browser/ui/browser_tabstrip.h" | 
| 33 #include "chrome/browser/ui/browser_window.h" | 34 #include "chrome/browser/ui/browser_window.h" | 
| 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 
| 35 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" | 
| 36 #include "chrome/test/base/in_process_browser_test.h" | 37 #include "chrome/test/base/in_process_browser_test.h" | 
| 37 #include "components/browsing_data/core/browsing_data_utils.h" | 38 #include "components/browsing_data/core/browsing_data_utils.h" | 
| 38 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" | 
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 398         base::Bind(&SdchBrowserTest::GetNumberOfDictionaryFetchesOnIOThread, | 399         base::Bind(&SdchBrowserTest::GetNumberOfDictionaryFetchesOnIOThread, | 
| 399                    base::Unretained(this), | 400                    base::Unretained(this), | 
| 400                    base::Unretained(profile->GetRequestContext()), | 401                    base::Unretained(profile->GetRequestContext()), | 
| 401                    &fetches), | 402                    &fetches), | 
| 402         run_loop.QuitClosure()); | 403         run_loop.QuitClosure()); | 
| 403     run_loop.Run(); | 404     run_loop.Run(); | 
| 404     DCHECK_NE(-1, fetches); | 405     DCHECK_NE(-1, fetches); | 
| 405     return fetches; | 406     return fetches; | 
| 406   } | 407   } | 
| 407 | 408 | 
| 408   void BrowsingDataRemoveAndWait(int remove_mask) { | 409   void BrowsingDataRemoveAndWait( | 
|  | 410       const std::set<const content::BrowsingDataType*>& remove_mask) { | 
| 409     BrowsingDataRemover* remover = | 411     BrowsingDataRemover* remover = | 
| 410         BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 412         BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 
| 411     BrowsingDataRemoverCompletionObserver completion_observer(remover); | 413     BrowsingDataRemoverCompletionObserver completion_observer(remover); | 
| 412     remover->RemoveAndReply( | 414     remover->RemoveAndReply( | 
| 413         browsing_data::CalculateBeginDeleteTime(browsing_data::LAST_HOUR), | 415         browsing_data::CalculateBeginDeleteTime(browsing_data::LAST_HOUR), | 
| 414         browsing_data::CalculateEndDeleteTime(browsing_data::LAST_HOUR), | 416         browsing_data::CalculateEndDeleteTime(browsing_data::LAST_HOUR), | 
| 415         remove_mask, BrowsingDataHelper::UNPROTECTED_WEB, &completion_observer); | 417         remove_mask, BrowsingDataHelper::UNPROTECTED_WEB, &completion_observer); | 
| 416     completion_observer.BlockUntilCompletion(); | 418     completion_observer.BlockUntilCompletion(); | 
| 417   } | 419   } | 
| 418 | 420 | 
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 667 const char SdchBrowserTest::kTestHost[] = "our.test.host.com"; | 669 const char SdchBrowserTest::kTestHost[] = "our.test.host.com"; | 
| 668 | 670 | 
| 669 // Confirm that after getting a dictionary, calling the browsing | 671 // Confirm that after getting a dictionary, calling the browsing | 
| 670 // data remover renders it unusable.  Also (in calling | 672 // data remover renders it unusable.  Also (in calling | 
| 671 // ForceSdchDictionaryLoad()) servers as a smoke test for SDCH. | 673 // ForceSdchDictionaryLoad()) servers as a smoke test for SDCH. | 
| 672 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, BrowsingDataRemover) { | 674 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, BrowsingDataRemover) { | 
| 673   ASSERT_TRUE(ForceSdchDictionaryLoad(browser())); | 675   ASSERT_TRUE(ForceSdchDictionaryLoad(browser())); | 
| 674 | 676 | 
| 675   // Confirm browsing data remover without removing the cache leaves | 677   // Confirm browsing data remover without removing the cache leaves | 
| 676   // SDCH alone. | 678   // SDCH alone. | 
| 677   BrowsingDataRemoveAndWait(BrowsingDataRemover::REMOVE_ALL & | 679   std::set<const content::BrowsingDataType*> mask = BrowsingDataTypeSetAll(); | 
| 678                             ~BrowsingDataRemover::REMOVE_CACHE); | 680   mask.erase(&kBrowsingDataTypeCache); | 
|  | 681   BrowsingDataRemoveAndWait(mask); | 
| 679   bool sdch_encoding_used = false; | 682   bool sdch_encoding_used = false; | 
| 680   ASSERT_TRUE(GetData(&sdch_encoding_used)); | 683   ASSERT_TRUE(GetData(&sdch_encoding_used)); | 
| 681   EXPECT_TRUE(sdch_encoding_used); | 684   EXPECT_TRUE(sdch_encoding_used); | 
| 682 | 685 | 
| 683   // Confirm browsing data remover removing the cache clears SDCH state. | 686   // Confirm browsing data remover removing the cache clears SDCH state. | 
| 684   BrowsingDataRemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); | 687   BrowsingDataRemoveAndWait({&kBrowsingDataTypeCache}); | 
| 685   sdch_encoding_used = false; | 688   sdch_encoding_used = false; | 
| 686   ASSERT_TRUE(GetData(&sdch_encoding_used)); | 689   ASSERT_TRUE(GetData(&sdch_encoding_used)); | 
| 687   EXPECT_FALSE(sdch_encoding_used); | 690   EXPECT_FALSE(sdch_encoding_used); | 
| 688 } | 691 } | 
| 689 | 692 | 
| 690 // Confirm dictionaries not visible in other profiles. | 693 // Confirm dictionaries not visible in other profiles. | 
| 691 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, Isolation) { | 694 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, Isolation) { | 
| 692   ASSERT_TRUE(ForceSdchDictionaryLoad(browser())); | 695   ASSERT_TRUE(ForceSdchDictionaryLoad(browser())); | 
| 693   ASSERT_TRUE(SetupSecondBrowser()); | 696   ASSERT_TRUE(SetupSecondBrowser()); | 
| 694   ASSERT_TRUE(SetupIncognitoBrowser()); | 697   ASSERT_TRUE(SetupIncognitoBrowser()); | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 712   ASSERT_TRUE(SetupIncognitoBrowser()); | 715   ASSERT_TRUE(SetupIncognitoBrowser()); | 
| 713   ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser())); | 716   ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser())); | 
| 714 | 717 | 
| 715   // Data fetches on main browser should not be SDCH encoded. | 718   // Data fetches on main browser should not be SDCH encoded. | 
| 716   bool sdch_encoding_used = true; | 719   bool sdch_encoding_used = true; | 
| 717   ASSERT_TRUE(GetData(&sdch_encoding_used)); | 720   ASSERT_TRUE(GetData(&sdch_encoding_used)); | 
| 718   EXPECT_FALSE(sdch_encoding_used); | 721   EXPECT_FALSE(sdch_encoding_used); | 
| 719 } | 722 } | 
| 720 | 723 | 
| 721 }  // namespace | 724 }  // namespace | 
| OLD | NEW | 
|---|