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

Side by Side Diff: chrome/browser/ui/webui/print_preview_ui_unittest.cc

Issue 7063030: PrintPreview: Print Preview is not staying associated with initiator renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 6 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) 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/shared_memory.h" 6 #include "base/memory/ref_counted_memory.h"
7 #include "chrome/browser/printing/print_preview_tab_controller.h" 7 #include "chrome/browser/printing/print_preview_tab_controller.h"
8 #include "chrome/browser/ui/browser_list.h" 8 #include "chrome/browser/ui/browser_list.h"
9 #include "chrome/browser/ui/webui/print_preview_ui.h" 9 #include "chrome/browser/ui/webui/print_preview_ui.h"
10 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h"
11 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
12 #include "chrome/test/browser_with_test_window_test.h" 11 #include "chrome/test/browser_with_test_window_test.h"
13 #include "chrome/test/testing_profile.h" 12 #include "chrome/test/testing_profile.h"
14 #include "content/browser/tab_contents/tab_contents.h" 13 #include "content/browser/tab_contents/tab_contents.h"
15 14
16 typedef BrowserWithTestWindowTest PrintPreviewUIHTMLSourceTest; 15 namespace {
16
17 const unsigned char blob1[] =
18 "12346102356120394751634516591348710478123649165419234519234512349134";
19
20 } // namespace
21
22 typedef BrowserWithTestWindowTest PrintPreviewUITest;
17 23
18 // Create/Get a preview tab for initiator tab. 24 // Create/Get a preview tab for initiator tab.
19 TEST_F(PrintPreviewUIHTMLSourceTest, PrintPreviewData) { 25 TEST_F(PrintPreviewUITest, PrintPreviewData) {
20 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS) 26 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS)
21 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePrintPreview); 27 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePrintPreview);
22 #endif 28 #endif
23 ASSERT_TRUE(browser()); 29 ASSERT_TRUE(browser());
24 BrowserList::SetLastActive(browser()); 30 BrowserList::SetLastActive(browser());
25 ASSERT_TRUE(BrowserList::GetLastActive()); 31 ASSERT_TRUE(BrowserList::GetLastActive());
26 32
27 browser()->NewTab(); 33 browser()->NewTab();
28 TabContents* initiator_tab = browser()->GetSelectedTabContents(); 34 TabContents* initiator_tab = browser()->GetSelectedTabContents();
29 ASSERT_TRUE(initiator_tab); 35 ASSERT_TRUE(initiator_tab);
30 36
31 scoped_refptr<printing::PrintPreviewTabController> 37 scoped_refptr<printing::PrintPreviewTabController>
32 controller(new printing::PrintPreviewTabController()); 38 controller(new printing::PrintPreviewTabController());
33 ASSERT_TRUE(controller); 39 ASSERT_TRUE(controller);
34 40
35 TabContents* preview_tab = controller->GetOrCreatePreviewTab(initiator_tab); 41 TabContents* preview_tab = controller->GetOrCreatePreviewTab(initiator_tab);
36 42
37 EXPECT_NE(initiator_tab, preview_tab); 43 EXPECT_NE(initiator_tab, preview_tab);
38 EXPECT_EQ(2, browser()->tab_count()); 44 EXPECT_EQ(2, browser()->tab_count());
39 45
40 PrintPreviewUI* preview_ui = 46 PrintPreviewUI* preview_ui =
41 reinterpret_cast<PrintPreviewUI*>(preview_tab->web_ui()); 47 reinterpret_cast<PrintPreviewUI*>(preview_tab->web_ui());
42 ASSERT_TRUE(preview_ui != NULL); 48 ASSERT_TRUE(preview_ui != NULL);
43 PrintPreviewUIHTMLSource* html_source = preview_ui->html_source();
44 49
45 PrintPreviewUIHTMLSource::PrintPreviewData data; 50 scoped_refptr<RefCountedBytes> data(new RefCountedBytes);
46 html_source->GetPrintPreviewData(&data); 51 preview_ui->GetPrintPreviewData(&data);
47 EXPECT_EQ(NULL, data.first); 52 EXPECT_EQ(NULL, data->front());
48 EXPECT_EQ(0U, data.second); 53 EXPECT_EQ(0U, data->size());
49 54
50 PrintPreviewUIHTMLSource::PrintPreviewData dummy_data = 55 std::vector<unsigned char> preview_data(blob1, blob1 + sizeof(blob1));
51 std::make_pair(new base::SharedMemory(), 1234); 56 scoped_refptr<RefCountedBytes> dummy_data(new RefCountedBytes(preview_data));
52 57
53 html_source->SetPrintPreviewData(dummy_data); 58 preview_ui->SetPrintPreviewData(dummy_data.get());
54 html_source->GetPrintPreviewData(&data); 59 preview_ui->GetPrintPreviewData(&data);
55 EXPECT_EQ(dummy_data, data); 60 EXPECT_EQ(dummy_data->size(), data->size());
61 EXPECT_EQ(dummy_data.get(), data.get());
56 62
57 // This should not cause any memory leaks. 63 // This should not cause any memory leaks.
58 dummy_data.first = new base::SharedMemory(); 64 dummy_data = new RefCountedBytes();
59 html_source->SetPrintPreviewData(dummy_data); 65 preview_ui->SetPrintPreviewData(dummy_data);
60 } 66 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview_ui_html_source_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698