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

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

Issue 17500003: Close web contents modal dialogs on content load start (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bonus patchset: initiator tab -> initiator Created 7 years, 5 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_dialog_controller.h" 6 #include "chrome/browser/printing/print_preview_dialog_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/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 bool dialog_destroyed() { return dialog_destroyed_; } 43 bool dialog_destroyed() { return dialog_destroyed_; }
44 44
45 private: 45 private:
46 virtual void WebContentsDestroyed(WebContents* contents) OVERRIDE { 46 virtual void WebContentsDestroyed(WebContents* contents) OVERRIDE {
47 dialog_destroyed_ = true; 47 dialog_destroyed_ = true;
48 } 48 }
49 49
50 bool dialog_destroyed_; 50 bool dialog_destroyed_;
51 }; 51 };
52 52
53 // Test to verify that when a initiator tab navigates, we can create a new 53 // Test to verify that when a initiator navigates, we can create a new preview
54 // preview dialog for the new tab contents. 54 // dialog for the new tab contents.
55 IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest, 55 IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
56 NavigateFromInitiatorTab) { 56 NavigateFromInitiator) {
57 // Create a reference to initiator tab contents. 57 // Create a reference to initiator contents.
58 WebContents* initiator_tab = 58 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();
59 browser()->tab_strip_model()->GetActiveWebContents(); 59 ASSERT_TRUE(initiator);
60 ASSERT_TRUE(initiator_tab);
61 60
62 printing::PrintPreviewDialogController* dialog_controller = 61 printing::PrintPreviewDialogController* dialog_controller =
63 printing::PrintPreviewDialogController::GetInstance(); 62 printing::PrintPreviewDialogController::GetInstance();
64 ASSERT_TRUE(dialog_controller); 63 ASSERT_TRUE(dialog_controller);
65 64
66 // Get the preview dialog for the initiator tab. 65 // Get the preview dialog for the initiator.
67 printing::PrintViewManager* print_view_manager = 66 printing::PrintViewManager* print_view_manager =
68 printing::PrintViewManager::FromWebContents(initiator_tab); 67 printing::PrintViewManager::FromWebContents(initiator);
69 print_view_manager->PrintPreviewNow(false); 68 print_view_manager->PrintPreviewNow(false);
70 WebContents* preview_dialog = 69 WebContents* preview_dialog =
71 dialog_controller->GetOrCreatePreviewDialog(initiator_tab); 70 dialog_controller->GetOrCreatePreviewDialog(initiator);
72 71
73 // Check a new print preview dialog got created. 72 // Check a new print preview dialog got created.
74 ASSERT_TRUE(preview_dialog); 73 ASSERT_TRUE(preview_dialog);
75 ASSERT_NE(initiator_tab, preview_dialog); 74 ASSERT_NE(initiator, preview_dialog);
76 75
77 // Navigate in the initiator tab. Make sure navigating destroys the print 76 // Navigate in the initiator. Make sure navigating destroys the print preview
78 // preview dialog. 77 // dialog.
79 PrintPreviewDialogDestroyedObserver observer(preview_dialog); 78 PrintPreviewDialogDestroyedObserver observer(preview_dialog);
80 GURL url(chrome::kChromeUINewTabURL); 79 GURL url(chrome::kChromeUINewTabURL);
81 ui_test_utils::NavigateToURL(browser(), url); 80 ui_test_utils::NavigateToURL(browser(), url);
82 ASSERT_TRUE(observer.dialog_destroyed()); 81 ASSERT_TRUE(observer.dialog_destroyed());
83 82
84 // Get the print preview dialog for the initiator tab. 83 // Get the print preview dialog for the initiator.
85 print_view_manager->PrintPreviewNow(false); 84 print_view_manager->PrintPreviewNow(false);
86 WebContents* new_preview_dialog = 85 WebContents* new_preview_dialog =
87 dialog_controller->GetOrCreatePreviewDialog(initiator_tab); 86 dialog_controller->GetOrCreatePreviewDialog(initiator);
88 87
89 // Check a new preview dialog got created. 88 // Check a new preview dialog got created.
90 EXPECT_TRUE(new_preview_dialog); 89 EXPECT_TRUE(new_preview_dialog);
91 } 90 }
92 91
93 // Test to verify that after reloading the initiator tab, it creates a new 92 // Test to verify that after reloading the initiator, it creates a new print
94 // print preview dialog. 93 // preview dialog.
95 IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest, 94 IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
96 ReloadInitiatorTab) { 95 ReloadInitiator) {
97 // Create a reference to initiator tab contents. 96 // Create a reference to initiator contents.
98 WebContents* initiator_tab = 97 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();
99 browser()->tab_strip_model()->GetActiveWebContents(); 98 ASSERT_TRUE(initiator);
100 ASSERT_TRUE(initiator_tab);
101 99
102 printing::PrintPreviewDialogController* dialog_controller = 100 printing::PrintPreviewDialogController* dialog_controller =
103 printing::PrintPreviewDialogController::GetInstance(); 101 printing::PrintPreviewDialogController::GetInstance();
104 ASSERT_TRUE(dialog_controller); 102 ASSERT_TRUE(dialog_controller);
105 103
106 // Create a preview dialog for the initiator tab. 104 // Create a preview dialog for the initiator.
107 printing::PrintViewManager* print_view_manager = 105 printing::PrintViewManager* print_view_manager =
108 printing::PrintViewManager::FromWebContents(initiator_tab); 106 printing::PrintViewManager::FromWebContents(initiator);
109 print_view_manager->PrintPreviewNow(false); 107 print_view_manager->PrintPreviewNow(false);
110 WebContents* preview_dialog = 108 WebContents* preview_dialog =
111 dialog_controller->GetOrCreatePreviewDialog(initiator_tab); 109 dialog_controller->GetOrCreatePreviewDialog(initiator);
112 110
113 // Check a new print preview dialog got created. 111 // Check a new print preview dialog got created.
114 ASSERT_TRUE(preview_dialog); 112 ASSERT_TRUE(preview_dialog);
115 ASSERT_NE(initiator_tab, preview_dialog); 113 ASSERT_NE(initiator, preview_dialog);
116 114
117 // Reload the initiator tab. Make sure reloading destroys the print preview 115 // Reload the initiator. Make sure reloading destroys the print preview
118 // dialog. 116 // dialog.
119 PrintPreviewDialogDestroyedObserver dialog_destroyed_observer(preview_dialog); 117 PrintPreviewDialogDestroyedObserver dialog_destroyed_observer(preview_dialog);
120 content::WindowedNotificationObserver notification_observer( 118 content::WindowedNotificationObserver notification_observer(
121 content::NOTIFICATION_LOAD_STOP, 119 content::NOTIFICATION_LOAD_STOP,
122 content::NotificationService::AllSources()); 120 content::NotificationService::AllSources());
123 chrome::Reload(browser(), CURRENT_TAB); 121 chrome::Reload(browser(), CURRENT_TAB);
124 notification_observer.Wait(); 122 notification_observer.Wait();
125 ASSERT_TRUE(dialog_destroyed_observer.dialog_destroyed()); 123 ASSERT_TRUE(dialog_destroyed_observer.dialog_destroyed());
126 124
127 // Create a preview dialog for the initiator tab. 125 // Create a preview dialog for the initiator.
128 print_view_manager->PrintPreviewNow(false); 126 print_view_manager->PrintPreviewNow(false);
129 WebContents* new_preview_dialog = 127 WebContents* new_preview_dialog =
130 dialog_controller->GetOrCreatePreviewDialog(initiator_tab); 128 dialog_controller->GetOrCreatePreviewDialog(initiator);
131 129
132 EXPECT_TRUE(new_preview_dialog); 130 EXPECT_TRUE(new_preview_dialog);
133 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698