OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/page_capture/page_capture_api.h" | 7 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.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/dns/mock_host_resolver.h" | 11 #include "net/dns/mock_host_resolver.h" |
12 | 12 |
13 using extensions::PageCaptureSaveAsMHTMLFunction; | 13 using extensions::PageCaptureSaveAsMHTMLFunction; |
14 | 14 |
15 class ExtensionPageCaptureApiTest : public ExtensionApiTest { | 15 class ExtensionPageCaptureApiTest : public ExtensionApiTest { |
16 public: | 16 public: |
17 virtual void SetUpCommandLine(CommandLine* command_line) override { | 17 void SetUpCommandLine(CommandLine* command_line) override { |
18 ExtensionApiTest::SetUpCommandLine(command_line); | 18 ExtensionApiTest::SetUpCommandLine(command_line); |
19 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); | 19 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); |
20 } | 20 } |
21 }; | 21 }; |
22 | 22 |
23 class PageCaptureSaveAsMHTMLDelegate | 23 class PageCaptureSaveAsMHTMLDelegate |
24 : public PageCaptureSaveAsMHTMLFunction::TestDelegate { | 24 : public PageCaptureSaveAsMHTMLFunction::TestDelegate { |
25 public: | 25 public: |
26 PageCaptureSaveAsMHTMLDelegate() { | 26 PageCaptureSaveAsMHTMLDelegate() { |
27 PageCaptureSaveAsMHTMLFunction::SetTestDelegate(this); | 27 PageCaptureSaveAsMHTMLFunction::SetTestDelegate(this); |
28 } | 28 } |
29 | 29 |
30 virtual ~PageCaptureSaveAsMHTMLDelegate() { | 30 virtual ~PageCaptureSaveAsMHTMLDelegate() { |
31 PageCaptureSaveAsMHTMLFunction::SetTestDelegate(NULL); | 31 PageCaptureSaveAsMHTMLFunction::SetTestDelegate(NULL); |
32 } | 32 } |
33 | 33 |
34 virtual void OnTemporaryFileCreated( | 34 void OnTemporaryFileCreated(const base::FilePath& temp_file) override { |
35 const base::FilePath& temp_file) override { | |
36 temp_file_ = temp_file; | 35 temp_file_ = temp_file; |
37 } | 36 } |
38 | 37 |
39 base::FilePath temp_file_; | 38 base::FilePath temp_file_; |
40 }; | 39 }; |
41 | 40 |
42 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest, SaveAsMHTML) { | 41 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest, SaveAsMHTML) { |
43 host_resolver()->AddRule("www.a.com", "127.0.0.1"); | 42 host_resolver()->AddRule("www.a.com", "127.0.0.1"); |
44 ASSERT_TRUE(StartEmbeddedTestServer()); | 43 ASSERT_TRUE(StartEmbeddedTestServer()); |
45 PageCaptureSaveAsMHTMLDelegate delegate; | 44 PageCaptureSaveAsMHTMLDelegate delegate; |
46 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_; | 45 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_; |
47 ASSERT_FALSE(delegate.temp_file_.empty()); | 46 ASSERT_FALSE(delegate.temp_file_.empty()); |
48 // Flush the message loops to make sure the delete happens. | 47 // Flush the message loops to make sure the delete happens. |
49 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 48 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
50 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); | 49 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); |
51 ASSERT_FALSE(base::PathExists(delegate.temp_file_)); | 50 ASSERT_FALSE(base::PathExists(delegate.temp_file_)); |
52 } | 51 } |
OLD | NEW |