summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-17 18:07:02 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-17 18:07:02 +0000
commit4cdac10757c9a774c3defdaf705f0d8c99290d19 (patch)
treed175d1d492401a5b96f3880df45c603fe05aee8a /chrome/test
parent09da32d543461c90fcf3490966e0c4a670b9a2a8 (diff)
downloadchromium_src-4cdac10757c9a774c3defdaf705f0d8c99290d19.zip
chromium_src-4cdac10757c9a774c3defdaf705f0d8c99290d19.tar.gz
chromium_src-4cdac10757c9a774c3defdaf705f0d8c99290d19.tar.bz2
Adds the anti-carpet bombing dialog. More specifically a new
EventHandler now exists between the buffered event handler and download event handler. This new event handler asks the DownloadRequestManager whether the download is allowed. This may prompt the user and then the download continues or is canceled. The DownloadRequestManager receives the request on the IO thread, forwards to the UI thread, makes the decision, then notifies back on the IO thread. BUG=3422 TEST=make sure you don't see any problems downloading content. Review URL: http://codereview.chromium.org/7479 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3543 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/test_tab_contents.cc38
-rw-r--r--chrome/test/test_tab_contents.h110
-rw-r--r--chrome/test/unit/unittests.vcproj16
3 files changed, 164 insertions, 0 deletions
diff --git a/chrome/test/test_tab_contents.cc b/chrome/test/test_tab_contents.cc
new file mode 100644
index 0000000..7b43b76
--- /dev/null
+++ b/chrome/test/test_tab_contents.cc
@@ -0,0 +1,38 @@
+// Copyright (c) 2006-2008 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 "chrome/test/test_tab_contents.h"
+
+#include "chrome/browser/navigation_entry.h"
+
+// static
+SiteInstance* TestTabContents::site_instance_ = NULL;
+
+TestTabContents::TestTabContents(TabContentsType type)
+ : TabContents(type),
+ commit_on_navigate_(false),
+ next_page_id_(1) {
+}
+
+bool TestTabContents::NavigateToPendingEntry(bool reload) {
+ if (commit_on_navigate_) {
+ CompleteNavigationAsRenderer(next_page_id_++,
+ controller()->GetPendingEntry()->url());
+ }
+ return true;
+}
+
+void TestTabContents::CompleteNavigationAsRenderer(int page_id,
+ const GURL& url) {
+ ViewHostMsg_FrameNavigate_Params params;
+ params.page_id = page_id;
+ params.url = url;
+ params.transition = PageTransition::LINK;
+ params.should_update_history = false;
+ params.gesture = NavigationGestureUser;
+ params.is_post = false;
+
+ NavigationController::LoadCommittedDetails details;
+ controller()->RendererDidNavigate(params, false, &details);
+}
diff --git a/chrome/test/test_tab_contents.h b/chrome/test/test_tab_contents.h
new file mode 100644
index 0000000..13b82e4
--- /dev/null
+++ b/chrome/test/test_tab_contents.h
@@ -0,0 +1,110 @@
+// Copyright (c) 2006-2008 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.
+
+#ifndef CHROME_BROWSER_TEST_TEST_TAB_CONTENTS_H_
+#define CHROME_BROWSER_TEST_TEST_TAB_CONTENTS_H_
+
+#include "base/string_util.h"
+#include "chrome/browser/tab_contents.h"
+#include "chrome/browser/tab_contents_factory.h"
+
+// TabContents typed created by TestTabContentsFactory.
+class TestTabContents : public TabContents {
+ public:
+ BEGIN_MSG_MAP(TestTabContents)
+ END_MSG_MAP()
+
+ explicit TestTabContents(TabContentsType type);
+
+ // Sets the site instance used by *ALL* TestTabContents.
+ static void set_site_instance(SiteInstance* site_instance) {
+ site_instance_ = site_instance;
+ }
+
+ // Sets whether we commit the load on NavigateToPendingEntry. The default is
+ // false.
+ void set_commit_on_navigate(bool commit_on_navigate) {
+ commit_on_navigate_ = commit_on_navigate;
+ }
+
+ // Overridden from TabContents so we can provide a non-NULL site instance in
+ // some cases. To use, the test will have to set the site_instance_ member
+ // variable to some site instance it creates.
+ virtual SiteInstance* GetSiteInstance() const {
+ return site_instance_;
+ }
+
+ // Does one of two things. If |commit_on_navigate| is true the navigation is
+ // committed immediately. Otherwise this returns true and you must invoke
+ // CompleteNavigationAsRenderer when you want to commit the load.
+ virtual bool NavigateToPendingEntry(bool reload);
+
+ // Sets up a call to RendererDidNavigate pretending to be a main frame
+ // navigation to the given URL.
+ void CompleteNavigationAsRenderer(int page_id, const GURL& url);
+
+ private:
+ static SiteInstance* site_instance_;
+
+ bool commit_on_navigate_;
+ int next_page_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestTabContents);
+};
+
+// TestTabContentsFactory is a TabContentsFactory that can be used for tests.
+//
+// Use the CreateAndRegisterFactory method to create and register a new
+// TestTabContentsFactory. You can use scheme() to determine the resulting
+// scheme and type() for the resulting TabContentsType.
+//
+// TestTabContentsFactory unregisters itself from the TabContentsFactory in its
+// destructor.
+class TestTabContentsFactory : public TabContentsFactory {
+ public:
+ // Creates a new TestTabContentsFactory and registers it for the next
+ // free TabContentsType. The destructor unregisters the factory.
+ static TestTabContentsFactory* CreateAndRegisterFactory() {
+ TabContentsType new_type = TabContentsFactory::NextUnusedType();
+ TestTabContentsFactory* new_factory =
+ new TestTabContentsFactory(
+ new_type, "test" + IntToString(static_cast<int>(new_type)));
+ TabContents::RegisterFactory(new_type, new_factory);
+ return new_factory;
+ }
+
+ TestTabContentsFactory(TabContentsType type, const std::string& scheme)
+ : type_(type),
+ scheme_(scheme) {
+ }
+
+ ~TestTabContentsFactory() {
+ TabContents::RegisterFactory(type_, NULL);
+ }
+
+ virtual TabContents* CreateInstance() {
+ return CreateInstanceImpl();
+ }
+
+ TestTabContents* CreateInstanceImpl() {
+ return new TestTabContents(type_);
+ }
+
+ virtual bool CanHandleURL(const GURL& url) {
+ return url.SchemeIs(scheme_.c_str());
+ }
+
+ const std::string& scheme() const { return scheme_; }
+
+ TabContentsType type() const { return type_; }
+
+ private:
+ TabContentsType type_;
+
+ const std::string scheme_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestTabContentsFactory);
+};
+
+#endif // CHROME_BROWSER_TEST_TEST_TAB_CONTENTS_H_
diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj
index df63415..b63c26e 100644
--- a/chrome/test/unit/unittests.vcproj
+++ b/chrome/test/unit/unittests.vcproj
@@ -198,6 +198,14 @@
>
</File>
<File
+ RelativePath="..\test_tab_contents.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\test_tab_contents.h"
+ >
+ </File>
+ <File
RelativePath="..\..\..\net\url_request\url_request_test_job.cc"
>
</File>
@@ -527,6 +535,14 @@
</File>
</Filter>
<Filter
+ Name="TestDownloadRequestManager"
+ >
+ <File
+ RelativePath="..\..\browser\download\download_request_manager_unittest.cc"
+ >
+ </File>
+ </Filter>
+ <Filter
Name="TestTemplateURLParser"
>
<File