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

Side by Side Diff: content/browser/browsing_data/clear_site_data_throttle_browsertest.cc

Issue 2933083002: Revert of Align `clear-site-data` syntax with the spec. (Closed)
Patch Set: Created 3 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/browsing_data/clear_site_data_throttle.h" 5 #include "content/browser/browsing_data/clear_site_data_throttle.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // information to the loaded website's title and C++ will wait until that 57 // information to the loaded website's title and C++ will wait until that
58 // happens. 58 // happens.
59 void WaitForTitle(const Shell* shell, const char* expected_title) { 59 void WaitForTitle(const Shell* shell, const char* expected_title) {
60 base::string16 expected_title_16 = base::ASCIIToUTF16(expected_title); 60 base::string16 expected_title_16 = base::ASCIIToUTF16(expected_title);
61 TitleWatcher title_watcher(shell->web_contents(), expected_title_16); 61 TitleWatcher title_watcher(shell->web_contents(), expected_title_16);
62 ASSERT_EQ(expected_title_16, title_watcher.WaitAndGetTitle()); 62 ASSERT_EQ(expected_title_16, title_watcher.WaitAndGetTitle());
63 } 63 }
64 64
65 // A value of the Clear-Site-Data header that requests cookie deletion. Reused 65 // A value of the Clear-Site-Data header that requests cookie deletion. Reused
66 // in tests that need a valid header but do not depend on its value. 66 // in tests that need a valid header but do not depend on its value.
67 static const char* kClearCookiesHeader = "\"cookies\""; 67 static const char* kClearCookiesHeader = "{ \"types\": [ \"cookies\" ] }";
68 68
69 // A helper class to observe BrowsingDataRemover deletion tasks coming from 69 // A helper class to observe BrowsingDataRemover deletion tasks coming from
70 // ClearSiteData. 70 // ClearSiteData.
71 class TestBrowsingDataRemoverDelegate : public MockBrowsingDataRemoverDelegate { 71 class TestBrowsingDataRemoverDelegate : public MockBrowsingDataRemoverDelegate {
72 public: 72 public:
73 // Sets a test expectation that a Clear-Site-Data header call from |origin|, 73 // Sets a test expectation that a Clear-Site-Data header call from |origin|,
74 // instructing to delete |cookies|, |storage|, and |cache|, will schedule 74 // instructing to delete |cookies|, |storage|, and |cache|, will schedule
75 // the corresponding BrowsingDataRemover deletion tasks. 75 // the corresponding BrowsingDataRemover deletion tasks.
76 void ExpectClearSiteDataCall(const url::Origin& origin, 76 void ExpectClearSiteDataCall(const url::Origin& origin,
77 bool cookies, 77 bool cookies,
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 // Tests that ClearSiteData() is called for the correct data types. 723 // Tests that ClearSiteData() is called for the correct data types.
724 IN_PROC_BROWSER_TEST_F(ClearSiteDataThrottleBrowserTest, Types) { 724 IN_PROC_BROWSER_TEST_F(ClearSiteDataThrottleBrowserTest, Types) {
725 GURL base_url = https_server()->GetURL("example.com", "/"); 725 GURL base_url = https_server()->GetURL("example.com", "/");
726 726
727 struct TestCase { 727 struct TestCase {
728 const char* value; 728 const char* value;
729 bool remove_cookies; 729 bool remove_cookies;
730 bool remove_storage; 730 bool remove_storage;
731 bool remove_cache; 731 bool remove_cache;
732 } test_cases[] = { 732 } test_cases[] = {
733 {"\"cookies\"", true, false, false}, 733 {"{ \"types\": [ \"cookies\" ] }", true, false, false},
734 {"\"storage\"", false, true, false}, 734 {"{ \"types\": [ \"storage\" ] }", false, true, false},
735 {"\"cache\"", false, false, true}, 735 {"{ \"types\": [ \"cache\" ] }", false, false, true},
736 {"\"cookies\", \"storage\"", true, true, false}, 736 {"{ \"types\": [ \"cookies\", \"storage\" ] }", true, true, false},
737 {"\"cookies\", \"cache\"", true, false, true}, 737 {"{ \"types\": [ \"cookies\", \"cache\" ] }", true, false, true},
738 {"\"storage\", \"cache\"", false, true, true}, 738 {"{ \"types\": [ \"storage\", \"cache\" ] }", false, true, true},
739 {"\"cookies\", \"storage\", \"cache\"", true, true, true}, 739 {"{ \"types\": [ \"cookies\", \"storage\", \"cache\" ] }", true, true,
740 true},
740 }; 741 };
741 742
742 for (const TestCase& test_case : test_cases) { 743 for (const TestCase& test_case : test_cases) {
743 GURL url = base_url; 744 GURL url = base_url;
744 AddQuery(&url, "header", test_case.value); 745 AddQuery(&url, "header", test_case.value);
745 746
746 delegate()->ExpectClearSiteDataCall( 747 delegate()->ExpectClearSiteDataCall(
747 url::Origin(url), test_case.remove_cookies, test_case.remove_storage, 748 url::Origin(url), test_case.remove_cookies, test_case.remove_storage,
748 test_case.remove_cache); 749 test_case.remove_cache);
749 750
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 786
786 // There are two service workers installed on two origins. 787 // There are two service workers installed on two origins.
787 std::vector<ServiceWorkerUsageInfo> service_workers = GetServiceWorkers(); 788 std::vector<ServiceWorkerUsageInfo> service_workers = GetServiceWorkers();
788 EXPECT_EQ(2u, service_workers.size()); 789 EXPECT_EQ(2u, service_workers.size());
789 790
790 // Navigate to a URL within the scope of "origin1.com" which responds with 791 // Navigate to a URL within the scope of "origin1.com" which responds with
791 // a Clear-Site-Data header. Verify that this did NOT remove the service 792 // a Clear-Site-Data header. Verify that this did NOT remove the service
792 // worker for "origin1.com", as the header would not be respected outside 793 // worker for "origin1.com", as the header would not be respected outside
793 // of the scope. 794 // of the scope.
794 GURL url = https_server()->GetURL("origin1.com", "/anything-in-the-scope"); 795 GURL url = https_server()->GetURL("origin1.com", "/anything-in-the-scope");
795 AddQuery(&url, "header", "\"storage\""); 796 AddQuery(&url, "header", "{ \"types\": [ \"storage\" ] }");
796 NavigateToURL(shell(), url); 797 NavigateToURL(shell(), url);
797 service_workers = GetServiceWorkers(); 798 service_workers = GetServiceWorkers();
798 EXPECT_EQ(2u, service_workers.size()); 799 EXPECT_EQ(2u, service_workers.size());
799 800
800 // This time, we will navigate to a URL on "origin1.com" that is not handled 801 // This time, we will navigate to a URL on "origin1.com" that is not handled
801 // by the serice worker, but results in a network request. One such resource 802 // by the serice worker, but results in a network request. One such resource
802 // not handled by "worker.js" is the path "resource". 803 // not handled by "worker.js" is the path "resource".
803 // The header will be respected and the worker deleted. 804 // The header will be respected and the worker deleted.
804 url = https_server()->GetURL("origin1.com", "/resource"); 805 url = https_server()->GetURL("origin1.com", "/resource");
805 AddQuery(&url, "header", "\"storage\""); 806 AddQuery(&url, "header", "{ \"types\": [ \"storage\" ] }");
806 NavigateToURL(shell(), url); 807 NavigateToURL(shell(), url);
807 808
808 // Only "origin2.com" now has a service worker. 809 // Only "origin2.com" now has a service worker.
809 service_workers = GetServiceWorkers(); 810 service_workers = GetServiceWorkers();
810 ASSERT_EQ(1u, service_workers.size()); 811 ASSERT_EQ(1u, service_workers.size());
811 EXPECT_EQ(service_workers[0].origin, 812 EXPECT_EQ(service_workers[0].origin,
812 https_server()->GetURL("origin2.com", "/")); 813 https_server()->GetURL("origin2.com", "/"));
813 814
814 // TODO(msramek): Test that the service worker update ping also deletes 815 // TODO(msramek): Test that the service worker update ping also deletes
815 // the service worker. 816 // the service worker.
(...skipping 20 matching lines...) Expand all
836 std::set<std::string> entries_to_create = {url1, url2, url3, url4}; 837 std::set<std::string> entries_to_create = {url1, url2, url3, url4};
837 util.CreateCacheEntries(entries_to_create); 838 util.CreateCacheEntries(entries_to_create);
838 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kTimeoutMs)); 839 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kTimeoutMs));
839 840
840 // There are four cache entries on two origins. 841 // There are four cache entries on two origins.
841 std::vector<std::string> cache_keys = util.GetEntryKeys(); 842 std::vector<std::string> cache_keys = util.GetEntryKeys();
842 EXPECT_EQ(4u, cache_keys.size()); 843 EXPECT_EQ(4u, cache_keys.size());
843 844
844 // Let Clear-Site-Data delete the "cache" of "origin1.com". 845 // Let Clear-Site-Data delete the "cache" of "origin1.com".
845 GURL url = https_server()->GetURL("origin1.com", "/clear-site-data"); 846 GURL url = https_server()->GetURL("origin1.com", "/clear-site-data");
846 AddQuery(&url, "header", "\"cache\""); 847 AddQuery(&url, "header", "{ \"types\": [ \"cache\" ] }");
847 NavigateToURL(shell(), url); 848 NavigateToURL(shell(), url);
848 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kTimeoutMs)); 849 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kTimeoutMs));
849 850
850 // Only "origin2.com" now has cache entries. 851 // Only "origin2.com" now has cache entries.
851 cache_keys = util.GetEntryKeys(); 852 cache_keys = util.GetEntryKeys();
852 ASSERT_EQ(2u, cache_keys.size()); 853 ASSERT_EQ(2u, cache_keys.size());
853 std::sort(cache_keys.begin(), cache_keys.end()); 854 std::sort(cache_keys.begin(), cache_keys.end());
854 EXPECT_EQ(url4, cache_keys[0]); 855 EXPECT_EQ(url4, cache_keys[0]);
855 EXPECT_EQ(url3, cache_keys[1]); 856 EXPECT_EQ(url3, cache_keys[1]);
856 } 857 }
857 858
858 // Tests that closing the tab right after executing Clear-Site-Data does 859 // Tests that closing the tab right after executing Clear-Site-Data does
859 // not crash. 860 // not crash.
860 IN_PROC_BROWSER_TEST_F(ClearSiteDataThrottleBrowserTest, ClosedTab) { 861 IN_PROC_BROWSER_TEST_F(ClearSiteDataThrottleBrowserTest, ClosedTab) {
861 GURL url = https_server()->GetURL("example.com", "/"); 862 GURL url = https_server()->GetURL("example.com", "/");
862 AddQuery(&url, "header", kClearCookiesHeader); 863 AddQuery(&url, "header", kClearCookiesHeader);
863 shell()->LoadURL(url); 864 shell()->LoadURL(url);
864 shell()->Close(); 865 shell()->Close();
865 } 866 }
866 867
867 } // namespace content 868 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698