OLD | NEW |
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 // Tests common functionality used by the Chrome Extensions Cookies API | 5 // Tests common functionality used by the Chrome Extensions Cookies API |
6 // implementation. | 6 // implementation. |
7 | 7 |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace keys = cookies_api_constants; | 26 namespace keys = cookies_api_constants; |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 struct DomainMatchCase { | 30 struct DomainMatchCase { |
31 const char* filter; | 31 const char* filter; |
32 const char* domain; | 32 const char* domain; |
33 const bool matches; | 33 const bool matches; |
34 }; | 34 }; |
35 | 35 |
36 // A test profile that supports linking with another profile for incognito | |
37 // support. | |
38 class OtrTestingProfile : public TestingProfile { | |
39 public: | |
40 OtrTestingProfile() : linked_profile_(NULL) {} | |
41 virtual Profile* GetOriginalProfile() OVERRIDE { | |
42 if (IsOffTheRecord()) | |
43 return linked_profile_; | |
44 else | |
45 return this; | |
46 } | |
47 | |
48 virtual Profile* GetOffTheRecordProfile() OVERRIDE { | |
49 if (IsOffTheRecord()) | |
50 return this; | |
51 else | |
52 return linked_profile_; | |
53 } | |
54 | |
55 virtual bool HasOffTheRecordProfile() OVERRIDE { | |
56 return (!IsOffTheRecord() && linked_profile_); | |
57 } | |
58 | |
59 static void LinkProfiles(OtrTestingProfile* profile1, | |
60 OtrTestingProfile* profile2) { | |
61 profile1->set_linked_profile(profile2); | |
62 profile2->set_linked_profile(profile1); | |
63 } | |
64 | |
65 void set_linked_profile(OtrTestingProfile* profile) { | |
66 linked_profile_ = profile; | |
67 } | |
68 | |
69 private: | |
70 OtrTestingProfile* linked_profile_; | |
71 }; | |
72 | |
73 } // namespace | 36 } // namespace |
74 | 37 |
75 class ExtensionCookiesTest : public testing::Test { | 38 class ExtensionCookiesTest : public testing::Test { |
76 }; | 39 }; |
77 | 40 |
78 TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) { | 41 TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) { |
79 OtrTestingProfile profile, otrProfile; | 42 TestingProfile::Builder profile_builder; |
80 otrProfile.set_incognito(true); | 43 TestingProfile::Builder otr_profile_builder; |
81 OtrTestingProfile::LinkProfiles(&profile, &otrProfile); | 44 otr_profile_builder.SetIncognito(); |
| 45 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
| 46 scoped_ptr<TestingProfile> otr_profile = otr_profile_builder.Build(); |
| 47 otr_profile->SetOriginalProfile(profile.get()); |
| 48 profile->SetOffTheRecordProfile(otr_profile.PassAs<Profile>()); |
82 | 49 |
83 EXPECT_EQ(std::string("0"), | 50 EXPECT_EQ(std::string("0"), |
84 cookies_helpers::GetStoreIdFromProfile(&profile)); | 51 cookies_helpers::GetStoreIdFromProfile(profile.get())); |
85 EXPECT_EQ(&profile, | 52 EXPECT_EQ(profile.get(), |
86 cookies_helpers::ChooseProfileFromStoreId( | 53 cookies_helpers::ChooseProfileFromStoreId( |
87 "0", &profile, true)); | 54 "0", profile.get(), true)); |
88 EXPECT_EQ(&profile, | 55 EXPECT_EQ(profile.get(), |
89 cookies_helpers::ChooseProfileFromStoreId( | 56 cookies_helpers::ChooseProfileFromStoreId( |
90 "0", &profile, false)); | 57 "0", profile.get(), false)); |
91 EXPECT_EQ(&otrProfile, | 58 EXPECT_EQ(profile->GetOffTheRecordProfile(), |
92 cookies_helpers::ChooseProfileFromStoreId( | 59 cookies_helpers::ChooseProfileFromStoreId( |
93 "1", &profile, true)); | 60 "1", profile.get(), true)); |
94 EXPECT_EQ(NULL, | 61 EXPECT_EQ(NULL, |
95 cookies_helpers::ChooseProfileFromStoreId( | 62 cookies_helpers::ChooseProfileFromStoreId( |
96 "1", &profile, false)); | 63 "1", profile.get(), false)); |
97 | 64 |
98 EXPECT_EQ(std::string("1"), | 65 EXPECT_EQ(std::string("1"), |
99 cookies_helpers::GetStoreIdFromProfile(&otrProfile)); | 66 cookies_helpers::GetStoreIdFromProfile( |
| 67 profile->GetOffTheRecordProfile())); |
100 EXPECT_EQ(NULL, | 68 EXPECT_EQ(NULL, |
101 cookies_helpers::ChooseProfileFromStoreId( | 69 cookies_helpers::ChooseProfileFromStoreId( |
102 "0", &otrProfile, true)); | 70 "0", profile->GetOffTheRecordProfile(), true)); |
103 EXPECT_EQ(NULL, | 71 EXPECT_EQ(NULL, |
104 cookies_helpers::ChooseProfileFromStoreId( | 72 cookies_helpers::ChooseProfileFromStoreId( |
105 "0", &otrProfile, false)); | 73 "0", profile->GetOffTheRecordProfile(), false)); |
106 EXPECT_EQ(&otrProfile, | 74 EXPECT_EQ(profile->GetOffTheRecordProfile(), |
107 cookies_helpers::ChooseProfileFromStoreId( | 75 cookies_helpers::ChooseProfileFromStoreId( |
108 "1", &otrProfile, true)); | 76 "1", profile->GetOffTheRecordProfile(), true)); |
109 EXPECT_EQ(&otrProfile, | 77 EXPECT_EQ(profile->GetOffTheRecordProfile(), |
110 cookies_helpers::ChooseProfileFromStoreId( | 78 cookies_helpers::ChooseProfileFromStoreId( |
111 "1", &otrProfile, false)); | 79 "1", profile->GetOffTheRecordProfile(), false)); |
112 } | 80 } |
113 | 81 |
114 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { | 82 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { |
115 net::CanonicalCookie canonical_cookie1( | 83 net::CanonicalCookie canonical_cookie1( |
116 GURL(), "ABC", "DEF", "www.foobar.com", "/", | 84 GURL(), "ABC", "DEF", "www.foobar.com", "/", |
117 base::Time(), base::Time(), base::Time(), | 85 base::Time(), base::Time(), base::Time(), |
118 false, false, net::COOKIE_PRIORITY_DEFAULT); | 86 false, false, net::COOKIE_PRIORITY_DEFAULT); |
119 scoped_ptr<Cookie> cookie1( | 87 scoped_ptr<Cookie> cookie1( |
120 cookies_helpers::CreateCookie( | 88 cookies_helpers::CreateCookie( |
121 canonical_cookie1, "some cookie store")); | 89 canonical_cookie1, "some cookie store")); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 false, | 193 false, |
226 net::COOKIE_PRIORITY_DEFAULT); | 194 net::COOKIE_PRIORITY_DEFAULT); |
227 scoped_ptr<Cookie> cookie( | 195 scoped_ptr<Cookie> cookie( |
228 cookies_helpers::CreateCookie( | 196 cookies_helpers::CreateCookie( |
229 canonical_cookie, "some cookie store")); | 197 canonical_cookie, "some cookie store")); |
230 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); | 198 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); |
231 EXPECT_EQ(std::string(), cookie->path); | 199 EXPECT_EQ(std::string(), cookie->path); |
232 } | 200 } |
233 | 201 |
234 } // namespace extensions | 202 } // namespace extensions |
OLD | NEW |