| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/printing/print_preview_tab_controller.h" | 9 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 10 #include "chrome/browser/printing/print_view_manager.h" | 10 #include "chrome/browser/printing/print_view_manager.h" |
| 11 #include "chrome/browser/ui/browser_commands.h" | 11 #include "chrome/browser/ui/browser_commands.h" |
| 12 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
| 13 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 13 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 15 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 15 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/test/base/browser_with_test_window_test.h" | 17 #include "chrome/test/base/browser_with_test_window_test.h" |
| 18 #include "content/public/browser/plugin_service.h" | |
| 19 #include "content/public/browser/site_instance.h" | 18 #include "content/public/browser/site_instance.h" |
| 20 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/test/web_contents_tester.h" | 20 #include "content/public/test/web_contents_tester.h" |
| 22 #include "printing/print_job_constants.h" | 21 #include "printing/print_job_constants.h" |
| 23 #include "webkit/plugins/npapi/mock_plugin_list.h" | |
| 24 | 22 |
| 25 using content::WebContents; | 23 using content::WebContents; |
| 26 using content::WebContentsTester; | 24 using content::WebContentsTester; |
| 27 | 25 |
| 28 namespace { | 26 namespace { |
| 29 | 27 |
| 30 base::RefCountedBytes* CreateTestData() { | 28 base::RefCountedBytes* CreateTestData() { |
| 31 const unsigned char blob1[] = | 29 const unsigned char blob1[] = |
| 32 "12346102356120394751634516591348710478123649165419234519234512349134"; | 30 "12346102356120394751634516591348710478123649165419234519234512349134"; |
| 33 std::vector<unsigned char> preview_data(blob1, blob1 + sizeof(blob1)); | 31 std::vector<unsigned char> preview_data(blob1, blob1 + sizeof(blob1)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 | 42 |
| 45 class PrintPreviewUIUnitTest : public BrowserWithTestWindowTest { | 43 class PrintPreviewUIUnitTest : public BrowserWithTestWindowTest { |
| 46 public: | 44 public: |
| 47 PrintPreviewUIUnitTest() {} | 45 PrintPreviewUIUnitTest() {} |
| 48 virtual ~PrintPreviewUIUnitTest() {} | 46 virtual ~PrintPreviewUIUnitTest() {} |
| 49 | 47 |
| 50 protected: | 48 protected: |
| 51 virtual void SetUp() OVERRIDE { | 49 virtual void SetUp() OVERRIDE { |
| 52 BrowserWithTestWindowTest::SetUp(); | 50 BrowserWithTestWindowTest::SetUp(); |
| 53 | 51 |
| 54 // The PluginService will be destroyed at the end of the test (due to the | |
| 55 // ShadowingAtExitManager in our base class). | |
| 56 content::PluginService::GetInstance()->SetPluginListForTesting( | |
| 57 &plugin_list_); | |
| 58 | |
| 59 profile()->GetPrefs()->SetBoolean(prefs::kPrintPreviewDisabled, false); | 52 profile()->GetPrefs()->SetBoolean(prefs::kPrintPreviewDisabled, false); |
| 60 | 53 |
| 61 chrome::NewTab(browser()); | 54 chrome::NewTab(browser()); |
| 62 } | 55 } |
| 63 | |
| 64 private: | |
| 65 webkit::npapi::MockPluginList plugin_list_; | |
| 66 }; | 56 }; |
| 67 | 57 |
| 68 // Create/Get a preview tab for initiator tab. | 58 // Create/Get a preview tab for initiator tab. |
| 69 TEST_F(PrintPreviewUIUnitTest, PrintPreviewData) { | 59 TEST_F(PrintPreviewUIUnitTest, PrintPreviewData) { |
| 70 TabContents* initiator_tab = chrome::GetActiveTabContents(browser()); | 60 TabContents* initiator_tab = chrome::GetActiveTabContents(browser()); |
| 71 ASSERT_TRUE(initiator_tab); | 61 ASSERT_TRUE(initiator_tab); |
| 72 EXPECT_EQ(0U, GetConstrainedWindowCount(initiator_tab)); | 62 EXPECT_EQ(0U, GetConstrainedWindowCount(initiator_tab)); |
| 73 | 63 |
| 74 printing::PrintPreviewTabController* controller = | 64 printing::PrintPreviewTabController* controller = |
| 75 printing::PrintPreviewTabController::GetInstance(); | 65 printing::PrintPreviewTabController::GetInstance(); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>( | 260 PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>( |
| 271 preview_tab->web_contents()->GetWebUI()->GetController()); | 261 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 272 ASSERT_TRUE(preview_ui != NULL); | 262 ASSERT_TRUE(preview_ui != NULL); |
| 273 | 263 |
| 274 preview_ui->OnPrintPreviewTabClosed(); | 264 preview_ui->OnPrintPreviewTabClosed(); |
| 275 | 265 |
| 276 EXPECT_EQ(2, browser()->tab_count()); | 266 EXPECT_EQ(2, browser()->tab_count()); |
| 277 EXPECT_EQ(0U, GetConstrainedWindowCount(initiator_tab)); | 267 EXPECT_EQ(0U, GetConstrainedWindowCount(initiator_tab)); |
| 278 EXPECT_EQ(1, initiator_tester->GetNumberOfFocusCalls()); | 268 EXPECT_EQ(1, initiator_tester->GetNumberOfFocusCalls()); |
| 279 } | 269 } |
| OLD | NEW |