This source file includes following definitions.
- file_size_
- MHTMLGenerated
- SetUp
- mhtml_generated
- file_size
- IN_PROC_BROWSER_TEST_F
#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
class MHTMLGenerationTest : public ContentBrowserTest {
public:
MHTMLGenerationTest() : mhtml_generated_(false), file_size_(0) {}
void MHTMLGenerated(int64 size) {
mhtml_generated_ = true;
file_size_ = size;
base::MessageLoopForUI::current()->Quit();
}
protected:
virtual void SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ContentBrowserTest::SetUp();
}
bool mhtml_generated() const { return mhtml_generated_; }
int64 file_size() const { return file_size_; }
base::ScopedTempDir temp_dir_;
private:
bool mhtml_generated_;
int64 file_size_;
};
IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
base::FilePath path(temp_dir_.path());
path = path.Append(FILE_PATH_LITERAL("test.mht"));
NavigateToURL(shell(), embedded_test_server()->GetURL("/simple_page.html"));
shell()->web_contents()->GenerateMHTML(
path, base::Bind(&MHTMLGenerationTest::MHTMLGenerated, this));
RunMessageLoop();
EXPECT_TRUE(mhtml_generated());
EXPECT_GT(file_size(), 0);
int64 file_size;
ASSERT_TRUE(base::GetFileSize(path, &file_size));
EXPECT_GT(file_size, 100);
}
}