Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: content/browser/download/mhtml_generation_browsertest.cc

Issue 8674002: Switch MHTMLGenerationManager to use a Callback. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_path.h" 6 #include "base/file_path.h"
6 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
7 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
8 #include "chrome/test/base/in_process_browser_test.h" 9 #include "chrome/test/base/in_process_browser_test.h"
9 #include "chrome/test/base/testing_browser_process.h" 10 #include "chrome/test/base/testing_browser_process.h"
10 #include "chrome/test/base/ui_test_utils.h" 11 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/browser/download/mhtml_generation_manager.h" 12 #include "content/browser/download/mhtml_generation_manager.h"
12 #include "content/browser/tab_contents/tab_contents.h" 13 #include "content/browser/tab_contents/tab_contents.h"
13 #include "content/public/browser/notification_types.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 namespace { 17 namespace {
18 18
19 class MHTMLGenerationTest : public InProcessBrowserTest { 19 class MHTMLGenerationTest : public InProcessBrowserTest {
20 public: 20 public:
21 MHTMLGenerationTest() {} 21 MHTMLGenerationTest() : mhtml_generated_(false), file_size_(0) {}
22
23 void MHTMLGenerated(const FilePath& path, int64 size) {
24 mhtml_generated_ = true;
25 file_size_ = size;
26 MessageLoopForUI::current()->Quit();
27 }
22 28
23 protected: 29 protected:
24 virtual void SetUp() { 30 virtual void SetUp() {
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
26 InProcessBrowserTest::SetUp(); 32 InProcessBrowserTest::SetUp();
27 } 33 }
28 34
35 bool mhtml_generated() const { return mhtml_generated_; }
36 int64 file_size() const { return file_size_; }
37
29 ScopedTempDir temp_dir_; 38 ScopedTempDir temp_dir_;
39
40 private:
41 bool mhtml_generated_;
42 int64 file_size_;
30 }; 43 };
31 44
32 // Tests that generating a MHTML does create contents. 45 // Tests that generating a MHTML does create contents.
33 // 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
34 // 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
35 // renderer. 48 // renderer.
36 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) { 49 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) {
37 ASSERT_TRUE(test_server()->Start()); 50 ASSERT_TRUE(test_server()->Start());
38 51
39 FilePath path(temp_dir_.path()); 52 FilePath path(temp_dir_.path());
40 path = path.Append(FILE_PATH_LITERAL("test.mht")); 53 path = path.Append(FILE_PATH_LITERAL("test.mht"));
41 54
42 ui_test_utils::NavigateToURL(browser(), 55 ui_test_utils::NavigateToURL(browser(),
43 test_server()->GetURL("files/google/google.html")); 56 test_server()->GetURL("files/google/google.html"));
44 57
45 TabContents* tab = browser()->GetSelectedTabContents(); 58 TabContents* tab = browser()->GetSelectedTabContents();
46 MHTMLGenerationManager* mhtml_generation_manager = 59 MHTMLGenerationManager* mhtml_generation_manager =
47 g_browser_process->mhtml_generation_manager(); 60 g_browser_process->mhtml_generation_manager();
48 61
49 content::Source<RenderViewHost> source(tab->render_view_host()); 62 mhtml_generation_manager->GenerateMHTML(tab, path,
50 ui_test_utils::WindowedNotificationObserverWithDetails< 63 base::Bind(&MHTMLGenerationTest::MHTMLGenerated, this));
51 MHTMLGenerationManager::NotificationDetails> signal(
52 content::NOTIFICATION_MHTML_GENERATED, source);
53 mhtml_generation_manager->GenerateMHTML(tab, path);
54 signal.Wait();
55 64
56 MHTMLGenerationManager::NotificationDetails details; 65 // Block until the MHTML is generated.
57 ASSERT_TRUE(signal.GetDetailsFor(source.map_key(), &details)); 66 ui_test_utils::RunMessageLoop();
58 ASSERT_GT(details.file_size, 0); 67
68 EXPECT_TRUE(mhtml_generated());
69 EXPECT_GT(file_size(), 0);
59 70
60 // Make sure the actual generated file has some contents. 71 // Make sure the actual generated file has some contents.
61 int64 file_size; 72 int64 file_size;
62 ASSERT_TRUE(file_util::GetFileSize(path, &file_size)); 73 ASSERT_TRUE(file_util::GetFileSize(path, &file_size));
63 EXPECT_GT(file_size, 100); 74 EXPECT_GT(file_size, 100);
64 } 75 }
65 76
66 } // namespace 77 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_save_page_api.cc ('k') | content/browser/download/mhtml_generation_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698