blob: 4a7e5da20279a70a6a30af8e81f7c2a428dff849 (
plain)
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
|
// Copyright (c) 2010 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/sys_string_conversions.h"
#include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#include "chrome/browser/ui/cocoa/cookie_details.h"
#include "chrome/browser/ui/cocoa/cookie_details_view_controller.h"
namespace {
class CookieDetailsViewControllerTest : public CocoaTest {
};
static CocoaCookieDetails* CreateTestCookieDetails(BOOL canEditExpiration) {
GURL url("http://chromium.org");
std::string cookieLine(
"PHPSESSID=0123456789abcdef0123456789abcdef; path=/");
net::CookieMonster::ParsedCookie pc(cookieLine);
net::CookieMonster::CanonicalCookie cookie(url, pc);
NSString* origin = base::SysUTF8ToNSString("http://chromium.org");
CocoaCookieDetails* details = [CocoaCookieDetails alloc];
[details initWithCookie:&cookie
origin:origin
canEditExpiration:canEditExpiration];
return [details autorelease];
}
static CookiePromptContentDetailsAdapter* CreateCookieTestContent(
BOOL canEditExpiration) {
CocoaCookieDetails* details = CreateTestCookieDetails(canEditExpiration);
return [[[CookiePromptContentDetailsAdapter alloc] initWithDetails:details]
autorelease];
}
static CocoaCookieDetails* CreateTestDatabaseDetails() {
std::string domain("chromium.org");
string16 name(base::SysNSStringToUTF16(@"wicked_name"));
string16 desc(base::SysNSStringToUTF16(@"wicked_desc"));
CocoaCookieDetails* details = [CocoaCookieDetails alloc];
[details initWithDatabase:domain
databaseName:name
databaseDescription:desc
fileSize:2222];
return [details autorelease];
}
static CookiePromptContentDetailsAdapter* CreateDatabaseTestContent() {
CocoaCookieDetails* details = CreateTestDatabaseDetails();
return [[[CookiePromptContentDetailsAdapter alloc] initWithDetails:details]
autorelease];
}
TEST_F(CookieDetailsViewControllerTest, Create) {
scoped_nsobject<CookieDetailsViewController> detailsViewController(
[[CookieDetailsViewController alloc] init]);
}
TEST_F(CookieDetailsViewControllerTest, ShrinkToFit) {
scoped_nsobject<CookieDetailsViewController> detailsViewController(
[[CookieDetailsViewController alloc] init]);
scoped_nsobject<CookiePromptContentDetailsAdapter> adapter(
[CreateDatabaseTestContent() retain]);
[detailsViewController.get() setContentObject:adapter.get()];
NSRect beforeFrame = [[detailsViewController.get() view] frame];
[detailsViewController.get() shrinkViewToFit];
NSRect afterFrame = [[detailsViewController.get() view] frame];
EXPECT_TRUE(afterFrame.size.height < beforeFrame.size.width);
}
TEST_F(CookieDetailsViewControllerTest, ExpirationEditability) {
scoped_nsobject<CookieDetailsViewController> detailsViewController(
[[CookieDetailsViewController alloc] init]);
[detailsViewController view];
scoped_nsobject<CookiePromptContentDetailsAdapter> adapter(
[CreateCookieTestContent(YES) retain]);
[detailsViewController.get() setContentObject:adapter.get()];
EXPECT_FALSE([detailsViewController.get() hasExpiration]);
[detailsViewController.get() setCookieHasExplicitExpiration:adapter.get()];
EXPECT_TRUE([detailsViewController.get() hasExpiration]);
[detailsViewController.get()
setCookieDoesntHaveExplicitExpiration:adapter.get()];
EXPECT_FALSE([detailsViewController.get() hasExpiration]);
}
} // namespace
|