diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-13 00:17:18 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-13 00:17:18 +0000 |
commit | 3f45e747058ff88d56ade868918d99f830d11df9 (patch) | |
tree | 9d27f816d82e7e4210f2a0a6672549c73dd60fdc /chrome/browser/blocked_popup_container_unittest.cc | |
parent | 6d21eb72d7333889badc108afe21dd1bc52e1135 (diff) | |
download | chromium_src-3f45e747058ff88d56ade868918d99f830d11df9.zip chromium_src-3f45e747058ff88d56ade868918d99f830d11df9.tar.gz chromium_src-3f45e747058ff88d56ade868918d99f830d11df9.tar.bz2 |
Create a basic test case for the common usage of BlockedPopupContainer.
Review URL: http://codereview.chromium.org/125083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18336 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/blocked_popup_container_unittest.cc')
-rw-r--r-- | chrome/browser/blocked_popup_container_unittest.cc | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/chrome/browser/blocked_popup_container_unittest.cc b/chrome/browser/blocked_popup_container_unittest.cc new file mode 100644 index 0000000..6d872f3 --- /dev/null +++ b/chrome/browser/blocked_popup_container_unittest.cc @@ -0,0 +1,102 @@ +// Copyright (c) 2009 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. + +// Tests the cross platform BlockedPopupContainer model/controller object. +// +// TODO(erg): The unit tests on BlockedPopupContainer need to be greatly +// expanded. + +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +#include "app/app_paths.h" +#include "base/path_service.h" +#include "chrome/browser/blocked_popup_container.h" +#include "chrome/browser/tab_contents/test_web_contents.h" +#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/test/testing_profile.h" +#include "net/base/net_util.h" + +namespace { +const std::string host1 = "host1"; +} // namespace + +// Mock for our view. +class MockBlockedPopupContainerView : public BlockedPopupContainerView { + public: + MOCK_METHOD0(SetPosition, void()); + MOCK_METHOD0(ShowView, void()); + MOCK_METHOD0(UpdateLabel, void()); + MOCK_METHOD0(HideView, void()); + MOCK_METHOD0(Destroy, void()); +}; + +class BlockedPopupContainerTest : public RenderViewHostTestHarness { + public: + TabContents* BuildTabContents() { + // This will be deleted when the TabContents goes away. + SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); + + // Set up and use TestTabContents here. + return new TestTabContents(profile_.get(), instance); + } + + GURL GetTestCase(const std::string& file) { + FilePath filename; + PathService::Get(app::DIR_TEST_DATA, &filename); + filename = filename.AppendASCII("constrained_files"); + filename = filename.AppendASCII(file); + return net::FilePathToFileURL(filename); + } + + protected: + virtual void SetUp() { + RenderViewHostTestHarness::SetUp(); + container_ = new BlockedPopupContainer(contents(), profile()->GetPrefs()); + container_->set_view(&mock); + + contents_->set_blocked_popup_container(container_); + } + + // Our blocked popup container that we are testing. WARNING: If you are + // trying to test destruction issues, make sure to remove |container_| from + // |contents_|. + BlockedPopupContainer* container_; + + // The mock that we're using. + MockBlockedPopupContainerView mock; +}; + +// Destroying the container should tell the View to destroy itself. +TEST_F(BlockedPopupContainerTest, TestDestroy) { + EXPECT_CALL(mock, Destroy()).Times(1); +} + +// Make sure TabContents::RepositionSupressedPopupsToFit() filters to the view. +TEST_F(BlockedPopupContainerTest, TestReposition) { + EXPECT_CALL(mock, SetPosition()).Times(1); + // Always need this to shut gmock up. :-/ + EXPECT_CALL(mock, Destroy()).Times(1); + + contents_->RepositionSupressedPopupsToFit(); +} + +// Test the basic blocked popup case. +TEST_F(BlockedPopupContainerTest, BasicCase) { + EXPECT_CALL(mock, UpdateLabel()).Times(1); + EXPECT_CALL(mock, ShowView()).Times(1); + EXPECT_CALL(mock, Destroy()).Times(1); + + // Create another TabContents representing the blocked popup case. + TabContents* popup = BuildTabContents(); + popup->controller().LoadURLLazily(GetTestCase("error"), GURL(), + PageTransition::LINK, + L"", NULL); + container_->AddTabContents(popup, gfx::Rect(), host1); + + EXPECT_EQ(container_->GetBlockedPopupCount(), static_cast<size_t>(1)); + EXPECT_EQ(container_->GetTabContentsAt(0), popup); + EXPECT_FALSE(container_->IsHostWhitelisted(0)); + EXPECT_THAT(container_->GetHosts(), testing::Contains(host1)); +} |