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
3 // found in the LICENSE file.
5 #include "base/base_switches.h"
6 #include "base/command_line.h"
7 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h"
8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "content/public/test/test_utils.h"
11 #include "net/dns/mock_host_resolver.h"
13 using extensions::PageCaptureSaveAsMHTMLFunction
;
15 class ExtensionPageCaptureApiTest
: public ExtensionApiTest
{
17 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
18 ExtensionApiTest::SetUpCommandLine(command_line
);
19 command_line
->AppendSwitchASCII(switches::kJavaScriptFlags
, "--expose-gc");
23 class PageCaptureSaveAsMHTMLDelegate
24 : public PageCaptureSaveAsMHTMLFunction::TestDelegate
{
26 PageCaptureSaveAsMHTMLDelegate() {
27 PageCaptureSaveAsMHTMLFunction::SetTestDelegate(this);
30 virtual ~PageCaptureSaveAsMHTMLDelegate() {
31 PageCaptureSaveAsMHTMLFunction::SetTestDelegate(NULL
);
34 void OnTemporaryFileCreated(const base::FilePath
& temp_file
) override
{
35 temp_file_
= temp_file
;
38 base::FilePath temp_file_
;
41 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest
, SaveAsMHTML
) {
42 host_resolver()->AddRule("www.a.com", "127.0.0.1");
43 ASSERT_TRUE(StartEmbeddedTestServer());
44 PageCaptureSaveAsMHTMLDelegate delegate
;
45 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_
;
46 ASSERT_FALSE(delegate
.temp_file_
.empty());
47 // Flush the message loops to make sure the delete happens.
48 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
49 content::RunAllPendingInMessageLoop(content::BrowserThread::IO
);
50 ASSERT_FALSE(base::PathExists(delegate
.temp_file_
));