blob: fbe9a1f6db989bff98ca2b4d19e2e584bece673f [file] [log] [blame]
[email protected]3bbacc5b2012-04-17 17:46:151// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]e7f009d2011-06-14 19:35:102// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]7477b2712011-11-23 07:53:035#include "base/bind.h"
[email protected]57999812013-02-24 05:40:526#include "base/files/file_path.h"
thestigb7aad54f2014-09-05 18:25:397#include "base/files/file_util.h"
[email protected]ea1a3f62012-11-16 20:34:238#include "base/files/scoped_temp_dir.h"
[email protected]4cdc9a22012-07-26 03:39:319#include "base/run_loop.h"
[email protected]4ca15302012-01-03 05:53:2010#include "content/public/browser/web_contents.h"
[email protected]6e9def12014-03-27 20:23:2811#include "content/public/test/content_browser_test.h"
12#include "content/public/test/content_browser_test_utils.h"
[email protected]4cdc9a22012-07-26 03:39:3113#include "content/public/test/test_utils.h"
[email protected]de7d61ff2013-08-20 11:30:4114#include "content/shell/browser/shell.h"
[email protected]0d31fbc2013-05-28 17:00:3715#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]e7f009d2011-06-14 19:35:1016#include "testing/gtest/include/gtest/gtest.h"
17
[email protected]4cdc9a22012-07-26 03:39:3118namespace content {
[email protected]4ca15302012-01-03 05:53:2019
[email protected]4cdc9a22012-07-26 03:39:3120class MHTMLGenerationTest : public ContentBrowserTest {
[email protected]e7f009d2011-06-14 19:35:1021 public:
[email protected]7477b2712011-11-23 07:53:0322 MHTMLGenerationTest() : mhtml_generated_(false), file_size_(0) {}
23
[email protected]18516cf92013-08-28 18:19:4824 void MHTMLGenerated(int64 size) {
[email protected]7477b2712011-11-23 07:53:0325 mhtml_generated_ = true;
26 file_size_ = size;
[email protected]dd32b1272013-05-04 14:17:1127 base::MessageLoopForUI::current()->Quit();
[email protected]7477b2712011-11-23 07:53:0328 }
[email protected]e7f009d2011-06-14 19:35:1029
30 protected:
dchengfa85b152014-10-28 01:13:4231 void SetUp() override {
[email protected]e7f009d2011-06-14 19:35:1032 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
[email protected]4cdc9a22012-07-26 03:39:3133 ContentBrowserTest::SetUp();
[email protected]e7f009d2011-06-14 19:35:1034 }
35
[email protected]7477b2712011-11-23 07:53:0336 bool mhtml_generated() const { return mhtml_generated_; }
37 int64 file_size() const { return file_size_; }
38
[email protected]ea1a3f62012-11-16 20:34:2339 base::ScopedTempDir temp_dir_;
[email protected]7477b2712011-11-23 07:53:0340
41 private:
42 bool mhtml_generated_;
43 int64 file_size_;
[email protected]e7f009d2011-06-14 19:35:1044};
45
46// Tests that generating a MHTML does create contents.
47// Note that the actual content of the file is not tested, the purpose of this
48// test is to ensure we were successfull in creating the MHTML data from the
49// renderer.
50IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) {
[email protected]0d31fbc2013-05-28 17:00:3751 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]e7f009d2011-06-14 19:35:1052
[email protected]2dec8ec2013-02-07 19:20:3453 base::FilePath path(temp_dir_.path());
[email protected]e7f009d2011-06-14 19:35:1054 path = path.Append(FILE_PATH_LITERAL("test.mht"));
55
[email protected]0d31fbc2013-05-28 17:00:3756 NavigateToURL(shell(), embedded_test_server()->GetURL("/simple_page.html"));
[email protected]e7f009d2011-06-14 19:35:1057
[email protected]4cdc9a22012-07-26 03:39:3158 shell()->web_contents()->GenerateMHTML(
59 path, base::Bind(&MHTMLGenerationTest::MHTMLGenerated, this));
[email protected]e7f009d2011-06-14 19:35:1060
[email protected]7477b2712011-11-23 07:53:0361 // Block until the MHTML is generated.
[email protected]35869622012-10-26 23:23:5562 RunMessageLoop();
[email protected]7477b2712011-11-23 07:53:0363
64 EXPECT_TRUE(mhtml_generated());
65 EXPECT_GT(file_size(), 0);
[email protected]e7f009d2011-06-14 19:35:1066
[email protected]3a605e82011-09-26 17:26:1667 // Make sure the actual generated file has some contents.
[email protected]e7f009d2011-06-14 19:35:1068 int64 file_size;
[email protected]56285702013-12-04 18:22:4969 ASSERT_TRUE(base::GetFileSize(path, &file_size));
[email protected]e7f009d2011-06-14 19:35:1070 EXPECT_GT(file_size, 100);
71}
72
[email protected]4cdc9a22012-07-26 03:39:3173} // namespace content