| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/base_switches.h" | 5 #include "base/base_switches.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_save_page_api.h" | 8 #include "chrome/browser/extensions/extension_page_capture_api.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "net/base/mock_host_resolver.h" | 11 #include "net/base/mock_host_resolver.h" |
| 12 | 12 |
| 13 class ExtensionSavePageApiTest : public ExtensionApiTest { | 13 class ExtensionPageCaptureApiTest : public ExtensionApiTest { |
| 14 public: | 14 public: |
| 15 // TODO(jcivelli): remove this once save-page APIs are no longer experimental. | |
| 16 virtual void SetUpCommandLine(CommandLine* command_line) { | 15 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 17 ExtensionApiTest::SetUpCommandLine(command_line); | 16 ExtensionApiTest::SetUpCommandLine(command_line); |
| 18 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | |
| 19 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); | 17 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); |
| 20 } | 18 } |
| 21 | 19 |
| 22 virtual void SetUpInProcessBrowserTestFixture() { | 20 virtual void SetUpInProcessBrowserTestFixture() { |
| 23 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 21 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 24 | 22 |
| 25 host_resolver()->AddRule("www.a.com", "127.0.0.1"); | 23 host_resolver()->AddRule("www.a.com", "127.0.0.1"); |
| 26 | 24 |
| 27 ASSERT_TRUE(StartTestServer()); | 25 ASSERT_TRUE(StartTestServer()); |
| 28 } | 26 } |
| 29 }; | 27 }; |
| 30 | 28 |
| 31 // Disabled on Linux http://crbug.com/98194 | 29 // Disabled on Linux http://crbug.com/98194 |
| 32 #if defined(OS_LINUX) | 30 #if defined(OS_LINUX) |
| 33 #define MAYBE_SavePageAsMHTML DISABLED_SavePageAsMHTML | 31 #define MAYBE_SaveAsMHTML DISABLED_SaveAsMHTML |
| 34 #else | 32 #else |
| 35 #define MAYBE_SavePageAsMHTML SavePageAsMHTML | 33 #define MAYBE_SaveAsMHTML SaveAsMHTML |
| 36 #endif // defined(OS_LINUX) | 34 #endif // defined(OS_LINUX) |
| 37 | 35 |
| 38 class SavePageAsMHTMLDelegate : public SavePageAsMHTMLFunction::TestDelegate { | 36 class PageCaptureSaveAsMHTMLDelegate |
| 37 : public PageCaptureSaveAsMHTMLFunction::TestDelegate { |
| 39 public: | 38 public: |
| 40 SavePageAsMHTMLDelegate() { | 39 PageCaptureSaveAsMHTMLDelegate() { |
| 41 SavePageAsMHTMLFunction::SetTestDelegate(this); | 40 PageCaptureSaveAsMHTMLFunction::SetTestDelegate(this); |
| 42 } | 41 } |
| 43 | 42 |
| 44 virtual ~SavePageAsMHTMLDelegate() { | 43 virtual ~PageCaptureSaveAsMHTMLDelegate() { |
| 45 SavePageAsMHTMLFunction::SetTestDelegate(NULL); | 44 PageCaptureSaveAsMHTMLFunction::SetTestDelegate(NULL); |
| 46 } | 45 } |
| 47 | 46 |
| 48 virtual void OnTemporaryFileCreated(const FilePath& temp_file) OVERRIDE { | 47 virtual void OnTemporaryFileCreated(const FilePath& temp_file) OVERRIDE { |
| 49 temp_file_ = temp_file; | 48 temp_file_ = temp_file; |
| 50 } | 49 } |
| 51 | 50 |
| 52 FilePath temp_file_; | 51 FilePath temp_file_; |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 IN_PROC_BROWSER_TEST_F(ExtensionSavePageApiTest, MAYBE_SavePageAsMHTML) { | 54 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest, SaveAsMHTML) { |
| 56 SavePageAsMHTMLDelegate delegate; | 55 PageCaptureSaveAsMHTMLDelegate delegate; |
| 57 ASSERT_TRUE(RunExtensionTest("save_page")) << message_; | 56 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_; |
| 58 ASSERT_FALSE(delegate.temp_file_.empty()); | 57 ASSERT_FALSE(delegate.temp_file_.empty()); |
| 59 // Flush the file message loop to make sure the delete happens. | 58 // Flush the file message loop to make sure the delete happens. |
| 60 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 59 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 61 ASSERT_FALSE(file_util::PathExists(delegate.temp_file_)); | 60 ASSERT_FALSE(file_util::PathExists(delegate.temp_file_)); |
| 62 | |
| 63 } | 61 } |
| OLD | NEW |