1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/strings/sys_string_conversions.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#include "chrome/browser/ui/cocoa/content_settings/cookie_details.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/parsed_cookie.h"
#import "testing/gtest_mac.h"
#include "url/gurl.h"
namespace {
class CookiesDetailsTest : public CocoaTest {
};
TEST_F(CookiesDetailsTest, CreateForFolder) {
base::scoped_nsobject<CocoaCookieDetails> details;
details.reset([[CocoaCookieDetails alloc] initAsFolder]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeFolder);
}
TEST_F(CookiesDetailsTest, CreateForCookie) {
base::scoped_nsobject<CocoaCookieDetails> details;
GURL url("http://chromium.org");
std::string cookieLine(
"PHPSESSID=0123456789abcdef0123456789abcdef; path=/");
net::ParsedCookie pc(cookieLine);
net::CanonicalCookie cookie(url, pc);
details.reset([[CocoaCookieDetails alloc] initWithCookie:&cookie
canEditExpiration:NO]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeCookie);
EXPECT_NSEQ(@"PHPSESSID", [details.get() name]);
EXPECT_NSEQ(@"0123456789abcdef0123456789abcdef",
[details.get() content]);
EXPECT_NSEQ(@"chromium.org", [details.get() domain]);
EXPECT_NSEQ(@"/", [details.get() path]);
EXPECT_NSNE(@"", [details.get() lastModified]);
EXPECT_NSNE(@"", [details.get() created]);
EXPECT_NSNE(@"", [details.get() sendFor]);
EXPECT_FALSE([details.get() shouldHideCookieDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowServiceWorkerTreeDetailsView]);
}
TEST_F(CookiesDetailsTest, CreateForTreeDatabase) {
base::scoped_nsobject<CocoaCookieDetails> details;
GURL origin("http://chromium.org");
std::string database_name("sassolungo");
std::string description("a great place to climb");
int64 size = 1234;
base::Time last_modified = base::Time::Now();
BrowsingDataDatabaseHelper::DatabaseInfo info(
storage::DatabaseIdentifier::CreateFromOrigin(origin),
database_name,
description,
size,
last_modified);
details.reset([[CocoaCookieDetails alloc] initWithDatabase:&info]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeDatabase);
EXPECT_NSEQ(@"a great place to climb", [details.get() databaseDescription]);
EXPECT_NSEQ(@"1,234 B", [details.get() fileSize]);
EXPECT_NSNE(@"", [details.get() lastModified]);
EXPECT_TRUE([details.get() shouldHideCookieDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]);
EXPECT_TRUE([details.get() shouldShowDatabaseTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowServiceWorkerTreeDetailsView]);
}
TEST_F(CookiesDetailsTest, CreateForTreeLocalStorage) {
base::scoped_nsobject<CocoaCookieDetails> details;
const GURL kOrigin("http://chromium.org/");
int64 size = 1234;
base::Time last_modified = base::Time::Now();
BrowsingDataLocalStorageHelper::LocalStorageInfo info(
kOrigin, size, last_modified);
details.reset([[CocoaCookieDetails alloc] initWithLocalStorage:&info]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeLocalStorage);
EXPECT_NSEQ(@"http://chromium.org/", [details.get() domain]);
EXPECT_NSEQ(@"1,234 B", [details.get() fileSize]);
EXPECT_NSNE(@"", [details.get() lastModified]);
EXPECT_TRUE([details.get() shouldHideCookieDetailsView]);
EXPECT_TRUE([details.get() shouldShowLocalStorageTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowServiceWorkerTreeDetailsView]);
}
TEST_F(CookiesDetailsTest, CreateForTreeAppCache) {
base::scoped_nsobject<CocoaCookieDetails> details;
GURL url("http://chromium.org/stuff.manifest");
content::AppCacheInfo info;
info.creation_time = base::Time::Now();
info.last_update_time = base::Time::Now();
info.last_access_time = base::Time::Now();
info.size=2678;
info.manifest_url = url;
details.reset([[CocoaCookieDetails alloc] initWithAppCacheInfo:&info]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeAppCache);
EXPECT_NSEQ(@"http://chromium.org/stuff.manifest",
[details.get() manifestURL]);
EXPECT_NSEQ(@"2,678 B", [details.get() fileSize]);
EXPECT_NSNE(@"", [details.get() lastAccessed]);
EXPECT_NSNE(@"", [details.get() created]);
EXPECT_TRUE([details.get() shouldHideCookieDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]);
EXPECT_TRUE([details.get() shouldShowAppCacheTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowServiceWorkerTreeDetailsView]);
}
TEST_F(CookiesDetailsTest, CreateForTreeIndexedDB) {
base::scoped_nsobject<CocoaCookieDetails> details;
GURL origin("http://moose.org/");
int64 size = 1234;
base::Time last_modified = base::Time::Now();
content::IndexedDBInfo info(origin,
size,
last_modified,
0);
details.reset([[CocoaCookieDetails alloc] initWithIndexedDBInfo:&info]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeIndexedDB);
EXPECT_NSEQ(@"http://moose.org/", [details.get() domain]);
EXPECT_NSEQ(@"1,234 B", [details.get() fileSize]);
EXPECT_NSNE(@"", [details.get() lastModified]);
EXPECT_TRUE([details.get() shouldHideCookieDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]);
EXPECT_TRUE([details.get() shouldShowIndexedDBTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowServiceWorkerTreeDetailsView]);
}
TEST_F(CookiesDetailsTest, CreateForPromptDatabase) {
base::scoped_nsobject<CocoaCookieDetails> details;
std::string domain("chromium.org");
base::string16 name(base::SysNSStringToUTF16(@"wicked_name"));
base::string16 desc(base::SysNSStringToUTF16(@"desc"));
details.reset([[CocoaCookieDetails alloc] initWithDatabase:domain
databaseName:name
databaseDescription:desc
fileSize:94]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptDatabase);
EXPECT_NSEQ(@"chromium.org", [details.get() domain]);
EXPECT_NSEQ(@"wicked_name", [details.get() name]);
EXPECT_NSEQ(@"desc", [details.get() databaseDescription]);
EXPECT_NSEQ(@"94 B", [details.get() fileSize]);
EXPECT_TRUE([details.get() shouldHideCookieDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]);
EXPECT_TRUE([details.get() shouldShowDatabasePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowServiceWorkerTreeDetailsView]);
}
TEST_F(CookiesDetailsTest, CreateForPromptLocalStorage) {
base::scoped_nsobject<CocoaCookieDetails> details;
std::string domain("chromium.org");
base::string16 key(base::SysNSStringToUTF16(@"testKey"));
base::string16 value(base::SysNSStringToUTF16(@"testValue"));
details.reset([[CocoaCookieDetails alloc] initWithLocalStorage:domain
key:key
value:value]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptLocalStorage);
EXPECT_NSEQ(@"chromium.org", [details.get() domain]);
EXPECT_NSEQ(@"testKey", [details.get() localStorageKey]);
EXPECT_NSEQ(@"testValue", [details.get() localStorageValue]);
EXPECT_TRUE([details.get() shouldHideCookieDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]);
EXPECT_TRUE([details.get() shouldShowLocalStoragePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowServiceWorkerTreeDetailsView]);
}
TEST_F(CookiesDetailsTest, CreateForPromptAppCache) {
base::scoped_nsobject<CocoaCookieDetails> details;
std::string manifestURL("http://html5demos.com/html5demo.manifest");
details.reset([[CocoaCookieDetails alloc]
initWithAppCacheManifestURL:manifestURL.c_str()]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptAppCache);
EXPECT_NSEQ(@"http://html5demos.com/html5demo.manifest",
[details.get() manifestURL]);
EXPECT_TRUE([details.get() shouldHideCookieDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]);
EXPECT_TRUE([details.get() shouldShowAppCachePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowServiceWorkerTreeDetailsView]);
}
TEST_F(CookiesDetailsTest, CreateForTreeServiceWorker) {
base::scoped_nsobject<CocoaCookieDetails> details;
GURL origin("https://example.com/");
std::vector<GURL> scopes;
scopes.push_back(GURL("https://example.com/app1/*"));
scopes.push_back(GURL("https://example.com/app2/*"));
content::ServiceWorkerUsageInfo info(origin,
scopes);
details.reset(
[[CocoaCookieDetails alloc] initWithServiceWorkerUsageInfo:&info]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeServiceWorker);
EXPECT_NSEQ(@"https://example.com/", [details.get() domain]);
EXPECT_NSEQ(@"https://example.com/app1/*,https://example.com/app2/*", [details.get() scopes]);
EXPECT_NSEQ(@"0 B", [details.get() fileSize]);
// TODO(jsbell): Plumb this through.
EXPECT_NSEQ(nil, [details.get() lastModified]);
EXPECT_TRUE([details.get() shouldHideCookieDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCacheTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowIndexedDBTreeDetailsView]);
EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]);
EXPECT_FALSE([details.get() shouldShowAppCachePromptDetailsView]);
EXPECT_TRUE([details.get() shouldShowServiceWorkerTreeDetailsView]);
}
}
|