| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 #include "base/sys_string_conversions.h" | |
| 6 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 7 #include "chrome/browser/ui/cocoa/cookie_details.h" | |
| 8 #include "googleurl/src/gurl.h" | |
| 9 #import "testing/gtest_mac.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 class CookiesDetailsTest : public CocoaTest { | |
| 14 }; | |
| 15 | |
| 16 TEST_F(CookiesDetailsTest, CreateForFolder) { | |
| 17 scoped_nsobject<CocoaCookieDetails> details; | |
| 18 details.reset([[CocoaCookieDetails alloc] initAsFolder]); | |
| 19 | |
| 20 EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeFolder); | |
| 21 } | |
| 22 | |
| 23 TEST_F(CookiesDetailsTest, CreateForCookie) { | |
| 24 scoped_nsobject<CocoaCookieDetails> details; | |
| 25 GURL url("http://chromium.org"); | |
| 26 std::string cookieLine( | |
| 27 "PHPSESSID=0123456789abcdef0123456789abcdef; path=/"); | |
| 28 net::CookieMonster::ParsedCookie pc(cookieLine); | |
| 29 net::CookieMonster::CanonicalCookie cookie(url, pc); | |
| 30 NSString* origin = base::SysUTF8ToNSString("http://chromium.org"); | |
| 31 details.reset([[CocoaCookieDetails alloc] initWithCookie:&cookie | |
| 32 origin:origin | |
| 33 canEditExpiration:NO]); | |
| 34 | |
| 35 EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeCookie); | |
| 36 EXPECT_NSEQ(@"PHPSESSID", [details.get() name]); | |
| 37 EXPECT_NSEQ(@"0123456789abcdef0123456789abcdef", | |
| 38 [details.get() content]); | |
| 39 EXPECT_NSEQ(@"http://chromium.org", [details.get() domain]); | |
| 40 EXPECT_NSEQ(@"/", [details.get() path]); | |
| 41 EXPECT_NSNE(@"", [details.get() lastModified]); | |
| 42 EXPECT_NSNE(@"", [details.get() created]); | |
| 43 EXPECT_NSNE(@"", [details.get() sendFor]); | |
| 44 | |
| 45 EXPECT_FALSE([details.get() shouldHideCookieDetailsView]); | |
| 46 EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); | |
| 47 EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); | |
| 48 EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]); | |
| 49 EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]); | |
| 50 EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); | |
| 51 EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); | |
| 52 EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]); | |
| 53 } | |
| 54 | |
| 55 TEST_F(CookiesDetailsTest, CreateForTreeDatabase) { | |
| 56 scoped_nsobject<CocoaCookieDetails> details; | |
| 57 std::string host("http://chromium.org"); | |
| 58 std::string database_name("sassolungo"); | |
| 59 std::string origin_identifier("dolomites"); | |
| 60 std::string description("a great place to climb"); | |
| 61 int64 size = 1234; | |
| 62 base::Time last_modified = base::Time::Now(); | |
| 63 BrowsingDataDatabaseHelper::DatabaseInfo info(host, database_name, | |
| 64 origin_identifier, description, host, size, last_modified); | |
| 65 details.reset([[CocoaCookieDetails alloc] initWithDatabase:&info]); | |
| 66 | |
| 67 EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeDatabase); | |
| 68 EXPECT_NSEQ(@"a great place to climb", [details.get() databaseDescription]); | |
| 69 EXPECT_NSEQ(@"1234 B", [details.get() fileSize]); | |
| 70 EXPECT_NSNE(@"", [details.get() lastModified]); | |
| 71 | |
| 72 EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); | |
| 73 EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); | |
| 74 EXPECT_TRUE([details.get() shouldShowDatabaseTreeDetailsView]); | |
| 75 EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]); | |
| 76 EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]); | |
| 77 EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); | |
| 78 EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); | |
| 79 EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]); | |
| 80 } | |
| 81 | |
| 82 TEST_F(CookiesDetailsTest, CreateForTreeLocalStorage) { | |
| 83 scoped_nsobject<CocoaCookieDetails> details; | |
| 84 std::string protocol("http"); | |
| 85 std::string host("chromium.org"); | |
| 86 unsigned short port = 80; | |
| 87 std::string database_identifier("id"); | |
| 88 std::string origin("chromium.org"); | |
| 89 FilePath file_path(FILE_PATH_LITERAL("/")); | |
| 90 int64 size = 1234; | |
| 91 base::Time last_modified = base::Time::Now(); | |
| 92 BrowsingDataLocalStorageHelper::LocalStorageInfo info(protocol, host, port, | |
| 93 database_identifier, origin, file_path, size, last_modified); | |
| 94 details.reset([[CocoaCookieDetails alloc] initWithLocalStorage:&info]); | |
| 95 | |
| 96 EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeLocalStorage); | |
| 97 EXPECT_NSEQ(@"chromium.org", [details.get() domain]); | |
| 98 EXPECT_NSEQ(@"1234 B", [details.get() fileSize]); | |
| 99 EXPECT_NSNE(@"", [details.get() lastModified]); | |
| 100 | |
| 101 EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); | |
| 102 EXPECT_TRUE([details.get() shouldShowLocalStorageTreeDetailsView]); | |
| 103 EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); | |
| 104 EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]); | |
| 105 EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]); | |
| 106 EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); | |
| 107 EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); | |
| 108 EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]); | |
| 109 } | |
| 110 | |
| 111 TEST_F(CookiesDetailsTest, CreateForTreeAppCache) { | |
| 112 scoped_nsobject<CocoaCookieDetails> details; | |
| 113 | |
| 114 GURL url("http://chromium.org/stuff.manifest"); | |
| 115 appcache::AppCacheInfo info; | |
| 116 info.creation_time = base::Time::Now(); | |
| 117 info.last_update_time = base::Time::Now(); | |
| 118 info.last_access_time = base::Time::Now(); | |
| 119 info.size=2678; | |
| 120 info.manifest_url = url; | |
| 121 details.reset([[CocoaCookieDetails alloc] initWithAppCacheInfo:&info]); | |
| 122 | |
| 123 EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeAppCache); | |
| 124 EXPECT_NSEQ(@"http://chromium.org/stuff.manifest", | |
| 125 [details.get() manifestURL]); | |
| 126 EXPECT_NSEQ(@"2678 B", [details.get() fileSize]); | |
| 127 EXPECT_NSNE(@"", [details.get() lastAccessed]); | |
| 128 EXPECT_NSNE(@"", [details.get() created]); | |
| 129 | |
| 130 EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); | |
| 131 EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); | |
| 132 EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); | |
| 133 EXPECT_TRUE([details.get() shouldShowAppCacheTreeDetailsView]); | |
| 134 EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]); | |
| 135 EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); | |
| 136 EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); | |
| 137 EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]); | |
| 138 } | |
| 139 | |
| 140 TEST_F(CookiesDetailsTest, CreateForTreeIndexedDB) { | |
| 141 scoped_nsobject<CocoaCookieDetails> details; | |
| 142 | |
| 143 std::string protocol("http"); | |
| 144 std::string host("moose.org"); | |
| 145 unsigned short port = 80; | |
| 146 std::string database_identifier("id"); | |
| 147 std::string origin("moose.org"); | |
| 148 FilePath file_path(FILE_PATH_LITERAL("/")); | |
| 149 int64 size = 1234; | |
| 150 base::Time last_modified = base::Time::Now(); | |
| 151 BrowsingDataIndexedDBHelper::IndexedDBInfo info(protocol, | |
| 152 host, | |
| 153 port, | |
| 154 database_identifier, | |
| 155 origin, | |
| 156 file_path, | |
| 157 size, | |
| 158 last_modified); | |
| 159 | |
| 160 details.reset([[CocoaCookieDetails alloc] initWithIndexedDBInfo:&info]); | |
| 161 | |
| 162 EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeIndexedDB); | |
| 163 EXPECT_NSEQ(@"moose.org", [details.get() domain]); | |
| 164 EXPECT_NSEQ(@"1234 B", [details.get() fileSize]); | |
| 165 EXPECT_NSNE(@"", [details.get() lastModified]); | |
| 166 | |
| 167 EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); | |
| 168 EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); | |
| 169 EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); | |
| 170 EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]); | |
| 171 EXPECT_TRUE([details.get() shouldShowIndexedDBTreeDetailsView]); | |
| 172 EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); | |
| 173 EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); | |
| 174 EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]); | |
| 175 } | |
| 176 | |
| 177 TEST_F(CookiesDetailsTest, CreateForPromptDatabase) { | |
| 178 scoped_nsobject<CocoaCookieDetails> details; | |
| 179 std::string domain("chromium.org"); | |
| 180 string16 name(base::SysNSStringToUTF16(@"wicked_name")); | |
| 181 string16 desc(base::SysNSStringToUTF16(@"desc")); | |
| 182 details.reset([[CocoaCookieDetails alloc] initWithDatabase:domain | |
| 183 databaseName:name | |
| 184 databaseDescription:desc | |
| 185 fileSize:94]); | |
| 186 | |
| 187 EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptDatabase); | |
| 188 EXPECT_NSEQ(@"chromium.org", [details.get() domain]); | |
| 189 EXPECT_NSEQ(@"wicked_name", [details.get() name]); | |
| 190 EXPECT_NSEQ(@"desc", [details.get() databaseDescription]); | |
| 191 EXPECT_NSEQ(@"94 B", [details.get() fileSize]); | |
| 192 | |
| 193 EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); | |
| 194 EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); | |
| 195 EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); | |
| 196 EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]); | |
| 197 EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]); | |
| 198 EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); | |
| 199 EXPECT_TRUE([details.get() shouldShowDatabasePromptDetailsView]); | |
| 200 EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]); | |
| 201 } | |
| 202 | |
| 203 TEST_F(CookiesDetailsTest, CreateForPromptLocalStorage) { | |
| 204 scoped_nsobject<CocoaCookieDetails> details; | |
| 205 std::string domain("chromium.org"); | |
| 206 string16 key(base::SysNSStringToUTF16(@"testKey")); | |
| 207 string16 value(base::SysNSStringToUTF16(@"testValue")); | |
| 208 details.reset([[CocoaCookieDetails alloc] initWithLocalStorage:domain | |
| 209 key:key | |
| 210 value:value]); | |
| 211 | |
| 212 EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptLocalStorage); | |
| 213 EXPECT_NSEQ(@"chromium.org", [details.get() domain]); | |
| 214 EXPECT_NSEQ(@"testKey", [details.get() localStorageKey]); | |
| 215 EXPECT_NSEQ(@"testValue", [details.get() localStorageValue]); | |
| 216 | |
| 217 EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); | |
| 218 EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); | |
| 219 EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); | |
| 220 EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]); | |
| 221 EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]); | |
| 222 EXPECT_TRUE([details.get() shouldShowLocalStoragePromptDetailsView]); | |
| 223 EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); | |
| 224 EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]); | |
| 225 } | |
| 226 | |
| 227 TEST_F(CookiesDetailsTest, CreateForPromptAppCache) { | |
| 228 scoped_nsobject<CocoaCookieDetails> details; | |
| 229 std::string manifestURL("http://html5demos.com/html5demo.manifest"); | |
| 230 details.reset([[CocoaCookieDetails alloc] | |
| 231 initWithAppCacheManifestURL:manifestURL.c_str()]); | |
| 232 | |
| 233 EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptAppCache); | |
| 234 EXPECT_NSEQ(@"http://html5demos.com/html5demo.manifest", | |
| 235 [details.get() manifestURL]); | |
| 236 | |
| 237 EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); | |
| 238 EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); | |
| 239 EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); | |
| 240 EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]); | |
| 241 EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]); | |
| 242 EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); | |
| 243 EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); | |
| 244 EXPECT_TRUE([details.get() shouldShowAppCachePromptDetailsView]); | |
| 245 } | |
| 246 | |
| 247 } | |
| OLD | NEW |