summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-31 22:54:35 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-31 22:54:35 +0000
commit1a37192a62bb8c6f212705c0df9c3c05bc1bf5e1 (patch)
treeb6c61a05654db7704b843a646c0b0ca060e3b5f7 /chrome
parent0899edb62bc0e042b04beafe8bc64e901c9542f4 (diff)
downloadchromium_src-1a37192a62bb8c6f212705c0df9c3c05bc1bf5e1.zip
chromium_src-1a37192a62bb8c6f212705c0df9c3c05bc1bf5e1.tar.gz
chromium_src-1a37192a62bb8c6f212705c0df9c3c05bc1bf5e1.tar.bz2
Convert parts of SavePage UI tests to more reliable browser tests.
Use a real notification for download completion - that's the main unflakying point. TEST=none http://crbug.com/3791 Review URL: http://codereview.chromium.org/160480 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22212 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/download/save_package.cc7
-rw-r--r--chrome/browser/download/save_page_browsertest.cc119
-rw-r--r--chrome/browser/download/save_page_uitest.cc50
-rw-r--r--chrome/chrome.gyp1
-rw-r--r--chrome/common/notification_type.h7
5 files changed, 134 insertions, 50 deletions
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index dcf8bdb..452a2ba 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -28,6 +28,8 @@
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_type.h"
#include "chrome/common/platform_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -601,6 +603,11 @@ void SavePackage::Finish() {
save_ids));
download_->Finished(all_save_items_count_);
+
+ NotificationService::current()->Notify(
+ NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
+ Source<SavePackage>(this),
+ Details<GURL>(&page_url_));
}
// Called for updating end state.
diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc
new file mode 100644
index 0000000..88859b3e
--- /dev/null
+++ b/chrome/browser/download/save_page_browsertest.cc
@@ -0,0 +1,119 @@
+// 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.
+
+#include "base/file_path.h"
+#include "base/scoped_temp_dir.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/net/url_request_mock_http_job.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page");
+
+namespace {
+
+class SavePageFinishedObserver : public NotificationObserver {
+ public:
+ SavePageFinishedObserver() {
+ registrar_.Add(this, NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
+ NotificationService::AllSources());
+ ui_test_utils::RunMessageLoop();
+ }
+
+ GURL page_url() const { return page_url_; }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED) {
+ page_url_ = *Details<GURL>(details).ptr();
+ MessageLoopForUI::current()->Quit();
+ } else {
+ NOTREACHED();
+ }
+ }
+
+ private:
+ NotificationRegistrar registrar_;
+
+ GURL page_url_;
+
+ DISALLOW_COPY_AND_ASSIGN(SavePageFinishedObserver);
+};
+
+class SavePageBrowserTest : public InProcessBrowserTest {
+ protected:
+ void SetUp() {
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_));
+ ASSERT_TRUE(save_dir_.CreateUniqueTempDir());
+ InProcessBrowserTest::SetUp();
+ }
+
+ // Path to directory containing test data.
+ FilePath test_dir_;
+
+ // Temporary directory we will save pages to.
+ ScopedTempDir save_dir_;
+};
+
+IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) {
+ FilePath file_name(FILE_PATH_LITERAL("a.htm"));
+ GURL url = URLRequestMockHTTPJob::GetMockUrl(
+ FilePath(kTestDir).Append(file_name).ToWStringHack());
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ TabContents* current_tab = browser()->GetSelectedTabContents();
+ ASSERT_TRUE(current_tab);
+
+ FilePath full_file_name = save_dir_.path().Append(file_name);
+ FilePath dir = save_dir_.path().AppendASCII("a_files");
+ current_tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(),
+ SavePackage::SAVE_AS_ONLY_HTML);
+
+ SavePageFinishedObserver observer;
+
+ EXPECT_EQ(url, observer.page_url());
+ EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
+ EXPECT_TRUE(file_util::PathExists(full_file_name));
+ EXPECT_FALSE(file_util::PathExists(dir));
+ EXPECT_TRUE(file_util::ContentsEqual(
+ test_dir_.Append(FilePath(kTestDir)).Append(file_name),
+ full_file_name));
+}
+
+IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) {
+ FilePath file_name(FILE_PATH_LITERAL("b.htm"));
+ GURL url = URLRequestMockHTTPJob::GetMockUrl(
+ FilePath(kTestDir).Append(file_name).ToWStringHack());
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ TabContents* current_tab = browser()->GetSelectedTabContents();
+ ASSERT_TRUE(current_tab);
+
+ FilePath full_file_name = save_dir_.path().Append(file_name);
+ FilePath dir = save_dir_.path().AppendASCII("b_files");
+ current_tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(),
+ SavePackage::SAVE_AS_COMPLETE_HTML);
+
+ SavePageFinishedObserver observer;
+
+ EXPECT_EQ(url, observer.page_url());
+ EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
+ EXPECT_TRUE(file_util::PathExists(full_file_name));
+ EXPECT_TRUE(file_util::PathExists(dir));
+ // TODO(phajdan.jr): Check saved html file's contents (http://crbug.com/3791).
+ EXPECT_TRUE(file_util::ContentsEqual(
+ test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
+ dir.AppendASCII("1.png")));
+ EXPECT_TRUE(file_util::ContentsEqual(
+ test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
+ dir.AppendASCII("1.css")));
+}
+
+} // namespace
diff --git a/chrome/browser/download/save_page_uitest.cc b/chrome/browser/download/save_page_uitest.cc
index 85f3b32..31a0fd6 100644
--- a/chrome/browser/download/save_page_uitest.cc
+++ b/chrome/browser/download/save_page_uitest.cc
@@ -84,56 +84,6 @@ class SavePageTest : public UITest {
FilePath download_dir_;
};
-// Flaky on Linux: http://code.google.com/p/chromium/issues/detail?id=14746
-TEST_F(SavePageTest, SaveHTMLOnly) {
- std::string file_name("a.htm");
- FilePath full_file_name = save_dir_.AppendASCII(file_name);
- FilePath dir = save_dir_.AppendASCII("a_files");
-
- GURL url = URLRequestMockHTTPJob::GetMockUrl(
- UTF8ToWide(std::string(kTestDir) + "/" + file_name));
- scoped_refptr<TabProxy> tab(GetActiveTab());
- ASSERT_TRUE(tab.get());
- ASSERT_TRUE(tab->NavigateToURL(url));
- WaitUntilTabCount(1);
-
- EXPECT_TRUE(tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(),
- SavePackage::SAVE_AS_ONLY_HTML));
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
-
- CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)),
- true);
- EXPECT_FALSE(file_util::PathExists(dir));
-}
-
-// Flaky on Linux: http://code.google.com/p/chromium/issues/detail?id=14746
-TEST_F(SavePageTest, SaveCompleteHTML) {
- std::string file_name = "b.htm";
- FilePath full_file_name = save_dir_.AppendASCII(file_name);
- FilePath dir = save_dir_.AppendASCII("b_files");
-
- GURL url = URLRequestMockHTTPJob::GetMockUrl(
- UTF8ToWide(std::string(kTestDir) + "/" + file_name));
- scoped_refptr<TabProxy> tab(GetActiveTab());
- ASSERT_TRUE(tab.get());
- ASSERT_TRUE(tab->NavigateToURL(url));
- WaitUntilTabCount(1);
-
- EXPECT_TRUE(tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(),
- SavePackage::SAVE_AS_COMPLETE_HTML));
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
-
- CheckFile(dir.AppendASCII("1.png"), FilePath(FILE_PATH_LITERAL("1.png")),
- true);
- CheckFile(dir.AppendASCII("1.css"), FilePath(FILE_PATH_LITERAL("1.css")),
- true);
- CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)),
- false);
- EXPECT_TRUE(file_util::DieFileDie(dir, true));
-}
-
TEST_F(SavePageTest, NoSave) {
std::string file_name = "c.htm";
FilePath full_file_name = save_dir_.AppendASCII(file_name);
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 2e27833..38c57c6 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -25,6 +25,7 @@
'browser_tests_sources': [
'browser/browser_browsertest.cc',
'browser/crash_recovery_browsertest.cc',
+ 'browser/download/save_page_browsertest.cc',
'browser/ssl/ssl_browser_tests.cc',
],
'browser_tests_sources_win_specific': [
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index 04fc94f..f4c296b 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -431,6 +431,13 @@ class NotificationType {
// No details are expected.
AUTH_SUPPLIED,
+ // Saved Pages -------------------------------------------------------------
+
+ // Sent when a SavePackage finishes successfully. The source is the
+ // SavePackage, and Details are a GURL containing address of downloaded
+ // page.
+ SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
+
// History -----------------------------------------------------------------
// Sent when a history service is created on the main thread. This is sent