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

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

Issue 6221005: Print Preview: Store preview data in the print preview controller.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/shared_memory.h"
5 #include "chrome/browser/printing/print_preview_tab_controller.h" 6 #include "chrome/browser/printing/print_preview_tab_controller.h"
6 #include "chrome/browser/tab_contents/tab_contents.h" 7 #include "chrome/browser/tab_contents/tab_contents.h"
7 #include "chrome/browser/tabs/tab_strip_model.h" 8 #include "chrome/browser/tabs/tab_strip_model.h"
8 #include "chrome/browser/ui/browser_list.h" 9 #include "chrome/browser/ui/browser_list.h"
9 #include "chrome/test/browser_with_test_window_test.h" 10 #include "chrome/test/browser_with_test_window_test.h"
10 #include "chrome/test/testing_profile.h" 11 #include "chrome/test/testing_profile.h"
11 12
12 typedef BrowserWithTestWindowTest PrintPreviewTabControllerTest; 13 typedef BrowserWithTestWindowTest PrintPreviewTabControllerTest;
13 14
14 // Create/Get a preview tab for initiator tab. 15 // Create/Get a preview tab for initiator tab.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 106
106 // Activate |tab_contents_1| tab. 107 // Activate |tab_contents_1| tab.
107 tab_contents_1->Activate(); 108 tab_contents_1->Activate();
108 109
109 // When we get the preview tab for |tab_contents_1|, 110 // When we get the preview tab for |tab_contents_1|,
110 // |preview_tab_1| is activated and focused. 111 // |preview_tab_1| is activated and focused.
111 tab_controller->GetOrCreatePreviewTab( 112 tab_controller->GetOrCreatePreviewTab(
112 tab_contents_1, tab_contents_1->controller().window_id().id()); 113 tab_contents_1, tab_contents_1->controller().window_id().id());
113 EXPECT_EQ(preview_tab_1_index, browser()->selected_index()); 114 EXPECT_EQ(preview_tab_1_index, browser()->selected_index());
114 } 115 }
116
117 // Tests {Get,Set}PrintPreviewData.
118 TEST_F(PrintPreviewTabControllerTest, PrintPreviewData) {
119 ASSERT_TRUE(browser());
120 BrowserList::SetLastActive(browser());
121 ASSERT_TRUE(BrowserList::GetLastActive());
122
123 browser()->NewTab();
124 TabContents* initiator_tab = browser()->GetSelectedTabContents();
125 ASSERT_TRUE(initiator_tab);
126
127 scoped_refptr<printing::PrintPreviewTabController>
128 controller(new printing::PrintPreviewTabController());
129 ASSERT_TRUE(controller);
130
131 TabContents* preview_tab = controller->GetOrCreatePreviewTab(
132 initiator_tab, initiator_tab->controller().window_id().id());
133
134 EXPECT_NE(initiator_tab, preview_tab);
135 EXPECT_EQ(2, browser()->tab_count());
136
137 printing::PrintPreviewTabController::PrintPreviewData data;
138 EXPECT_FALSE(controller->GetPrintPreviewData(NULL, &data));
139 EXPECT_FALSE(controller->GetPrintPreviewData(initiator_tab, &data));
140 EXPECT_TRUE(controller->GetPrintPreviewData(preview_tab, &data));
141 EXPECT_EQ(NULL, data.first);
142 EXPECT_EQ(0U, data.second);
143
144 printing::PrintPreviewTabController::PrintPreviewData dummy_data =
145 std::make_pair(new base::SharedMemory(), 1234);
146
147 EXPECT_FALSE(controller->SetPrintPreviewData(NULL, dummy_data));
148 EXPECT_FALSE(controller->SetPrintPreviewData(initiator_tab, dummy_data));
149 EXPECT_TRUE(controller->SetPrintPreviewData(preview_tab, dummy_data));
150
151 EXPECT_FALSE(controller->GetPrintPreviewData(NULL, &data));
152 EXPECT_FALSE(controller->GetPrintPreviewData(initiator_tab, &data));
153 EXPECT_TRUE(controller->GetPrintPreviewData(preview_tab, &data));
154 EXPECT_EQ(dummy_data, data);
155
156 // This should not cause any memory leaks.
157 dummy_data.first = new base::SharedMemory();
158 EXPECT_TRUE(controller->SetPrintPreviewData(preview_tab, dummy_data));
159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698