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

Side by Side Diff: chrome/browser/cocoa/blocked_popup_container_controller_unittest.mm

Issue 150132: First cut at popup blocking for Mac. Remove ifdefs in cross-platform code. Im... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 #import <Cocoa/Cocoa.h>
6
7 #include "app/app_paths.h"
8 #include "base/path_service.h"
9 #import "chrome/browser/cocoa/blocked_popup_container_controller.h"
10 #include "chrome/browser/cocoa/browser_test_helper.h"
11 #import "chrome/browser/cocoa/cocoa_test_helper.h"
12 #include "chrome/browser/renderer_host/test_render_view_host.h"
13 #include "net/base/net_util.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16
17 namespace {
18 const std::string host1 = "host1";
19 } // namespace
20
21 class BlockedPopupContainerControllerTest : public RenderViewHostTestHarness {
22 public:
23 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
24
25 virtual void SetUp() {
26 RenderViewHostTestHarness::SetUp();
27 container_ = BlockedPopupContainer::Create(contents(), profile());
28 cocoa_controller_ = [[BlockedPopupContainerController alloc]
29 initWithContainer:container_];
30 EXPECT_TRUE([cocoa_controller_ bridge]);
31 container_->set_view([cocoa_controller_ bridge]);
32 contents_->set_blocked_popup_container(container_);
33 }
34
35 virtual void TearDown() {
36 // This will also signal the Cocoa controller to delete itself with a
37 // Destroy() mesage to the bridge.
38 container_->Destroy();
39 contents_->set_blocked_popup_container(NULL);
40 }
41
42 TabContents* BuildTabContents() {
43 // This will be deleted when the TabContents goes away.
44 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get());
45
46 // Set up and use TestTabContents here.
47 return new TestTabContents(profile_.get(), instance);
48 }
49
50 GURL GetTestCase(const std::string& file) {
51 FilePath filename;
52 PathService::Get(app::DIR_TEST_DATA, &filename);
53 filename = filename.AppendASCII("constrained_files");
54 filename = filename.AppendASCII(file);
55 return net::FilePathToFileURL(filename);
56 }
57
58 BlockedPopupContainer* container_;
59 BlockedPopupContainerController* cocoa_controller_;
60 };
61
62 TEST_F(BlockedPopupContainerControllerTest, BasicPopupBlock) {
63 // This is taken from the popup blocker unit test.
64 TabContents* popup = BuildTabContents();
65 popup->controller().LoadURLLazily(GetTestCase("error"), GURL(),
66 PageTransition::LINK,
67 L"", NULL);
68 container_->AddTabContents(popup, gfx::Rect(), host1);
69 EXPECT_EQ(container_->GetBlockedPopupCount(), static_cast<size_t>(1));
70 EXPECT_EQ(container_->GetTabContentsAt(0), popup);
71 EXPECT_FALSE(container_->IsHostWhitelisted(0));
72
73 // Ensure the view has been displayed. If it has a superview, then ShowView()
74 // has been called on the bridge. If the label has a string, then
75 // UpdateLabel() has been called.
76 EXPECT_TRUE([cocoa_controller_ view]);
77 EXPECT_TRUE([[cocoa_controller_ view] superview]);
78 EXPECT_TRUE([[(NSTextField*)[cocoa_controller_ label]
79 stringValue] length] > 0);
80
81 // Close the popup and verify it's no longer in the view hierarchy. This
82 // means HideView() has been called.
83 [cocoa_controller_ closePopup:nil];
84 EXPECT_FALSE([[cocoa_controller_ view] superview]);
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698