| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "app/app_paths.h" | 7 #include "app/app_paths.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/scoped_nsautorelease_pool.h" | 9 #include "base/scoped_nsautorelease_pool.h" |
| 10 #import "chrome/browser/cocoa/blocked_popup_container_controller.h" | 10 #import "chrome/browser/cocoa/blocked_popup_container_controller.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 class BlockedPopupContainerControllerTest : public RenderViewHostTestHarness { | 22 class BlockedPopupContainerControllerTest : public RenderViewHostTestHarness { |
| 23 public: | 23 public: |
| 24 virtual void SetUp() { | 24 virtual void SetUp() { |
| 25 // This is all a bit convoluted because the standard factory Create() call | 25 // This is all a bit convoluted because the standard factory Create() call |
| 26 // doesn't give us access to the cocoa controller for testing (since it's | 26 // doesn't give us access to the cocoa controller for testing (since it's |
| 27 // an internal implementation detail). As a result, we need to create one | 27 // an internal implementation detail). As a result, we need to create one |
| 28 // separately and inject the bridge with a test-only Create() call. | 28 // separately and inject the bridge with a test-only Create() call. |
| 29 // Unfortunate, but no way around it. | 29 // Unfortunate, but no way around it. |
| 30 RenderViewHostTestHarness::SetUp(); | 30 RenderViewHostTestHarness::SetUp(); |
| 31 CocoaTest::BootstrapCocoa(); |
| 31 cocoa_controller_ = [[BlockedPopupContainerController alloc] | 32 cocoa_controller_ = [[BlockedPopupContainerController alloc] |
| 32 initWithContainer:nil]; | 33 initWithContainer:nil]; |
| 33 EXPECT_TRUE([cocoa_controller_ bridge]); | 34 EXPECT_TRUE([cocoa_controller_ bridge]); |
| 34 container_ = BlockedPopupContainer::Create(contents(), profile(), | 35 container_ = BlockedPopupContainer::Create(contents(), profile(), |
| 35 [cocoa_controller_ bridge]); | 36 [cocoa_controller_ bridge]); |
| 36 [cocoa_controller_ setContainer:container_]; | 37 [cocoa_controller_ setContainer:container_]; |
| 37 contents_->set_blocked_popup_container(container_); | 38 contents_->set_blocked_popup_container(container_); |
| 38 } | 39 } |
| 39 | 40 |
| 40 virtual void TearDown() { | 41 virtual void TearDown() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 | 56 |
| 56 GURL GetTestCase(const std::string& file) { | 57 GURL GetTestCase(const std::string& file) { |
| 57 FilePath filename; | 58 FilePath filename; |
| 58 PathService::Get(app::DIR_TEST_DATA, &filename); | 59 PathService::Get(app::DIR_TEST_DATA, &filename); |
| 59 filename = filename.AppendASCII("constrained_files"); | 60 filename = filename.AppendASCII("constrained_files"); |
| 60 filename = filename.AppendASCII(file); | 61 filename = filename.AppendASCII(file); |
| 61 return net::FilePathToFileURL(filename); | 62 return net::FilePathToFileURL(filename); |
| 62 } | 63 } |
| 63 | 64 |
| 64 base::ScopedNSAutoreleasePool pool; | 65 base::ScopedNSAutoreleasePool pool; |
| 65 CocoaTestHelper cocoa_helper_; | |
| 66 BlockedPopupContainer* container_; | 66 BlockedPopupContainer* container_; |
| 67 BlockedPopupContainerController* cocoa_controller_; | 67 BlockedPopupContainerController* cocoa_controller_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 TEST_F(BlockedPopupContainerControllerTest, BasicPopupBlock) { | 70 TEST_F(BlockedPopupContainerControllerTest, BasicPopupBlock) { |
| 71 // This is taken from the popup blocker unit test. | 71 // This is taken from the popup blocker unit test. |
| 72 TabContents* popup = BuildTabContents(); | 72 TabContents* popup = BuildTabContents(); |
| 73 popup->controller().LoadURL(GetTestCase("error"), GURL(), | 73 popup->controller().LoadURL(GetTestCase("error"), GURL(), |
| 74 PageTransition::LINK); | 74 PageTransition::LINK); |
| 75 container_->AddTabContents(popup, gfx::Rect(), host1); | 75 container_->AddTabContents(popup, gfx::Rect(), host1); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 96 menu = [cocoa_controller_ buildMenu]; | 96 menu = [cocoa_controller_ buildMenu]; |
| 97 EXPECT_TRUE(menu); | 97 EXPECT_TRUE(menu); |
| 98 EXPECT_EQ(2, [menu numberOfItems]); | 98 EXPECT_EQ(2, [menu numberOfItems]); |
| 99 EXPECT_EQ(NSOnState, [[menu itemAtIndex:1] state]); | 99 EXPECT_EQ(NSOnState, [[menu itemAtIndex:1] state]); |
| 100 | 100 |
| 101 // Close the popup and verify it's no longer in the view hierarchy. This | 101 // Close the popup and verify it's no longer in the view hierarchy. This |
| 102 // means HideView() has been called. | 102 // means HideView() has been called. |
| 103 [cocoa_controller_ closePopup:nil]; | 103 [cocoa_controller_ closePopup:nil]; |
| 104 EXPECT_FALSE([[cocoa_controller_ view] superview]); | 104 EXPECT_FALSE([[cocoa_controller_ view] superview]); |
| 105 } | 105 } |
| OLD | NEW |