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

Side by Side Diff: chrome/browser/printing/print_preview_tab_controller_browsertest.cc

Issue 10911351: Switch PrintViewManager, PrintPreviewMessageHandler to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, fix typo Created 8 years, 3 months 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 | Annotate | Revision Log
OLDNEW
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/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/printing/print_preview_tab_controller.h" 6 #include "chrome/browser/printing/print_preview_tab_controller.h"
7 #include "chrome/browser/printing/print_view_manager.h" 7 #include "chrome/browser/printing/print_view_manager.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h" 9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/browser_tabstrip.h" 10 #include "chrome/browser/ui/browser_tabstrip.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 // Create a reference to initiator tab contents. 60 // Create a reference to initiator tab contents.
61 TabContents* initiator_tab = chrome::GetActiveTabContents(browser()); 61 TabContents* initiator_tab = chrome::GetActiveTabContents(browser());
62 ASSERT_TRUE(initiator_tab); 62 ASSERT_TRUE(initiator_tab);
63 63
64 printing::PrintPreviewTabController* tab_controller = 64 printing::PrintPreviewTabController* tab_controller =
65 printing::PrintPreviewTabController::GetInstance(); 65 printing::PrintPreviewTabController::GetInstance();
66 ASSERT_TRUE(tab_controller); 66 ASSERT_TRUE(tab_controller);
67 67
68 // Get the preview tab for initiator tab. 68 // Get the preview tab for initiator tab.
69 initiator_tab->print_view_manager()->PrintPreviewNow(); 69 printing::PrintViewManager* print_view_manager =
70 printing::PrintViewManager::FromWebContents(
71 initiator_tab->web_contents());
72 print_view_manager->PrintPreviewNow();
70 TabContents* preview_tab = 73 TabContents* preview_tab =
71 tab_controller->GetOrCreatePreviewTab(initiator_tab); 74 tab_controller->GetOrCreatePreviewTab(initiator_tab);
72 75
73 // New print preview tab is created. 76 // New print preview tab is created.
74 EXPECT_EQ(1, browser()->tab_count()); 77 EXPECT_EQ(1, browser()->tab_count());
75 ASSERT_TRUE(preview_tab); 78 ASSERT_TRUE(preview_tab);
76 ASSERT_NE(initiator_tab, preview_tab); 79 ASSERT_NE(initiator_tab, preview_tab);
77 TabDestroyedObserver observer(preview_tab->web_contents()); 80 TabDestroyedObserver observer(preview_tab->web_contents());
78 81
79 // Navigate in the initiator tab. 82 // Navigate in the initiator tab.
80 GURL url(chrome::kChromeUINewTabURL); 83 GURL url(chrome::kChromeUINewTabURL);
81 ui_test_utils::NavigateToURL(browser(), url); 84 ui_test_utils::NavigateToURL(browser(), url);
82 85
83 ASSERT_TRUE(observer.tab_destroyed()); 86 ASSERT_TRUE(observer.tab_destroyed());
84 87
85 // Get the print preview tab for initiator tab. 88 // Get the print preview tab for initiator tab.
86 initiator_tab->print_view_manager()->PrintPreviewNow(); 89 print_view_manager->PrintPreviewNow();
87 TabContents* new_preview_tab = 90 TabContents* new_preview_tab =
88 tab_controller->GetOrCreatePreviewTab(initiator_tab); 91 tab_controller->GetOrCreatePreviewTab(initiator_tab);
89 92
90 // New preview tab is created. 93 // New preview tab is created.
91 EXPECT_EQ(1, browser()->tab_count()); 94 EXPECT_EQ(1, browser()->tab_count());
92 EXPECT_TRUE(new_preview_tab); 95 EXPECT_TRUE(new_preview_tab);
93 } 96 }
94 97
95 // Test to verify that after reloading the initiator tab, it creates a new 98 // Test to verify that after reloading the initiator tab, it creates a new
96 // print preview tab. 99 // print preview tab.
97 IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest, 100 IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest,
98 ReloadInitiatorTab) { 101 ReloadInitiatorTab) {
99 // Lets start with one tab. 102 // Lets start with one tab.
100 EXPECT_EQ(1, browser()->tab_count()); 103 EXPECT_EQ(1, browser()->tab_count());
101 104
102 // Create a reference to initiator tab contents. 105 // Create a reference to initiator tab contents.
103 TabContents* initiator_tab = chrome::GetActiveTabContents(browser()); 106 TabContents* initiator_tab = chrome::GetActiveTabContents(browser());
104 ASSERT_TRUE(initiator_tab); 107 ASSERT_TRUE(initiator_tab);
105 108
106 printing::PrintPreviewTabController* tab_controller = 109 printing::PrintPreviewTabController* tab_controller =
107 printing::PrintPreviewTabController::GetInstance(); 110 printing::PrintPreviewTabController::GetInstance();
108 ASSERT_TRUE(tab_controller); 111 ASSERT_TRUE(tab_controller);
109 112
110 // Get the preview tab for initiator tab. 113 // Get the preview tab for initiator tab.
111 initiator_tab->print_view_manager()->PrintPreviewNow(); 114 printing::PrintViewManager* print_view_manager =
115 printing::PrintViewManager::FromWebContents(
116 initiator_tab->web_contents());
117 print_view_manager->PrintPreviewNow();
112 TabContents* preview_tab = 118 TabContents* preview_tab =
113 tab_controller->GetOrCreatePreviewTab(initiator_tab); 119 tab_controller->GetOrCreatePreviewTab(initiator_tab);
114 120
115 // New print preview tab is created. 121 // New print preview tab is created.
116 EXPECT_EQ(1, browser()->tab_count()); 122 EXPECT_EQ(1, browser()->tab_count());
117 ASSERT_TRUE(preview_tab); 123 ASSERT_TRUE(preview_tab);
118 ASSERT_NE(initiator_tab, preview_tab); 124 ASSERT_NE(initiator_tab, preview_tab);
119 TabDestroyedObserver tab_destroyed_observer(preview_tab->web_contents()); 125 TabDestroyedObserver tab_destroyed_observer(preview_tab->web_contents());
120 126
121 // Reload the initiator tab. 127 // Reload the initiator tab.
122 content::WindowedNotificationObserver notification_observer( 128 content::WindowedNotificationObserver notification_observer(
123 content::NOTIFICATION_LOAD_STOP, 129 content::NOTIFICATION_LOAD_STOP,
124 content::NotificationService::AllSources()); 130 content::NotificationService::AllSources());
125 chrome::Reload(browser(), CURRENT_TAB); 131 chrome::Reload(browser(), CURRENT_TAB);
126 notification_observer.Wait(); 132 notification_observer.Wait();
127 133
128 ASSERT_TRUE(tab_destroyed_observer.tab_destroyed()); 134 ASSERT_TRUE(tab_destroyed_observer.tab_destroyed());
129 135
130 // Get the print preview tab for initiator tab. 136 // Get the print preview tab for initiator tab.
131 initiator_tab->print_view_manager()->PrintPreviewNow(); 137 print_view_manager->PrintPreviewNow();
132 TabContents* new_preview_tab = 138 TabContents* new_preview_tab =
133 tab_controller->GetOrCreatePreviewTab(initiator_tab); 139 tab_controller->GetOrCreatePreviewTab(initiator_tab);
134 140
135 EXPECT_EQ(1, browser()->tab_count()); 141 EXPECT_EQ(1, browser()->tab_count());
136 EXPECT_TRUE(new_preview_tab); 142 EXPECT_TRUE(new_preview_tab);
137 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698