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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/run_loop.h" |
7 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
8 #include "chrome/browser/ui/browser.h" | |
9 #include "chrome/browser/ui/browser_tabstrip.h" | |
10 #include "chrome/test/base/in_process_browser_test.h" | |
11 #include "chrome/test/base/testing_browser_process.h" | |
12 #include "chrome/test/base/ui_test_utils.h" | |
13 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/test/test_utils.h" |
| 11 #include "content/shell/shell.h" |
| 12 #include "content/test/content_browser_test.h" |
| 13 #include "content/test/content_browser_test_utils.h" |
14 #include "net/test/test_server.h" | 14 #include "net/test/test_server.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using content::WebContents; | 17 namespace content { |
18 | 18 |
19 namespace { | 19 class MHTMLGenerationTest : public ContentBrowserTest { |
20 | |
21 class MHTMLGenerationTest : public InProcessBrowserTest { | |
22 public: | 20 public: |
23 MHTMLGenerationTest() : mhtml_generated_(false), file_size_(0) {} | 21 MHTMLGenerationTest() : mhtml_generated_(false), file_size_(0) {} |
24 | 22 |
25 void MHTMLGenerated(const FilePath& path, int64 size) { | 23 void MHTMLGenerated(const FilePath& path, int64 size) { |
26 mhtml_generated_ = true; | 24 mhtml_generated_ = true; |
27 file_size_ = size; | 25 file_size_ = size; |
28 MessageLoopForUI::current()->Quit(); | 26 MessageLoopForUI::current()->Quit(); |
29 } | 27 } |
30 | 28 |
31 protected: | 29 protected: |
32 virtual void SetUp() { | 30 virtual void SetUp() { |
33 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
34 InProcessBrowserTest::SetUp(); | 32 ContentBrowserTest::SetUp(); |
35 } | 33 } |
36 | 34 |
37 bool mhtml_generated() const { return mhtml_generated_; } | 35 bool mhtml_generated() const { return mhtml_generated_; } |
38 int64 file_size() const { return file_size_; } | 36 int64 file_size() const { return file_size_; } |
39 | 37 |
40 ScopedTempDir temp_dir_; | 38 ScopedTempDir temp_dir_; |
41 | 39 |
42 private: | 40 private: |
43 bool mhtml_generated_; | 41 bool mhtml_generated_; |
44 int64 file_size_; | 42 int64 file_size_; |
45 }; | 43 }; |
46 | 44 |
47 // Tests that generating a MHTML does create contents. | 45 // Tests that generating a MHTML does create contents. |
48 // Note that the actual content of the file is not tested, the purpose of this | 46 // Note that the actual content of the file is not tested, the purpose of this |
49 // test is to ensure we were successfull in creating the MHTML data from the | 47 // test is to ensure we were successfull in creating the MHTML data from the |
50 // renderer. | 48 // renderer. |
51 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) { | 49 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) { |
52 ASSERT_TRUE(test_server()->Start()); | 50 ASSERT_TRUE(test_server()->Start()); |
53 | 51 |
54 FilePath path(temp_dir_.path()); | 52 FilePath path(temp_dir_.path()); |
55 path = path.Append(FILE_PATH_LITERAL("test.mht")); | 53 path = path.Append(FILE_PATH_LITERAL("test.mht")); |
56 | 54 |
57 ui_test_utils::NavigateToURL(browser(), | 55 NavigateToURL(shell(), test_server()->GetURL("files/simple_page.html")); |
58 test_server()->GetURL("files/google/google.html")); | |
59 | 56 |
60 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 57 shell()->web_contents()->GenerateMHTML( |
61 web_contents->GenerateMHTML(path, | 58 path, base::Bind(&MHTMLGenerationTest::MHTMLGenerated, this)); |
62 base::Bind(&MHTMLGenerationTest::MHTMLGenerated, | |
63 this)); | |
64 | 59 |
65 // Block until the MHTML is generated. | 60 // Block until the MHTML is generated. |
66 ui_test_utils::RunMessageLoop(); | 61 base::RunLoop run_loop; |
| 62 RunThisRunLoop(&run_loop); |
67 | 63 |
68 EXPECT_TRUE(mhtml_generated()); | 64 EXPECT_TRUE(mhtml_generated()); |
69 EXPECT_GT(file_size(), 0); | 65 EXPECT_GT(file_size(), 0); |
70 | 66 |
71 // Make sure the actual generated file has some contents. | 67 // Make sure the actual generated file has some contents. |
72 int64 file_size; | 68 int64 file_size; |
73 ASSERT_TRUE(file_util::GetFileSize(path, &file_size)); | 69 ASSERT_TRUE(file_util::GetFileSize(path, &file_size)); |
74 EXPECT_GT(file_size, 100); | 70 EXPECT_GT(file_size, 100); |
75 } | 71 } |
76 | 72 |
77 } // namespace | 73 } // namespace content |
OLD | NEW |