| 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/printing/print_preview_tab_controller.h" | 8 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 9 #include "chrome/browser/printing/print_preview_unit_test_base.h" | 9 #include "chrome/browser/printing/print_preview_unit_test_base.h" |
| 10 #include "chrome/browser/printing/print_view_manager.h" | 10 #include "chrome/browser/printing/print_view_manager.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 ASSERT_TRUE(controller); | 51 ASSERT_TRUE(controller); |
| 52 | 52 |
| 53 initiator_tab->print_view_manager()->PrintPreviewNow(); | 53 initiator_tab->print_view_manager()->PrintPreviewNow(); |
| 54 TabContentsWrapper* preview_tab = | 54 TabContentsWrapper* preview_tab = |
| 55 controller->GetOrCreatePreviewTab(initiator_tab); | 55 controller->GetOrCreatePreviewTab(initiator_tab); |
| 56 | 56 |
| 57 EXPECT_NE(initiator_tab, preview_tab); | 57 EXPECT_NE(initiator_tab, preview_tab); |
| 58 EXPECT_EQ(1, browser()->tab_count()); | 58 EXPECT_EQ(1, browser()->tab_count()); |
| 59 EXPECT_EQ(1U, GetConstrainedWindowCount(initiator_tab)); | 59 EXPECT_EQ(1U, GetConstrainedWindowCount(initiator_tab)); |
| 60 | 60 |
| 61 PrintPreviewUI* preview_ui = reinterpret_cast<PrintPreviewUI*>( | 61 PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>( |
| 62 preview_tab->web_contents()->GetWebUI()); | 62 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 63 ASSERT_TRUE(preview_ui != NULL); | 63 ASSERT_TRUE(preview_ui != NULL); |
| 64 | 64 |
| 65 scoped_refptr<RefCountedBytes> data; | 65 scoped_refptr<RefCountedBytes> data; |
| 66 preview_ui->GetPrintPreviewDataForIndex( | 66 preview_ui->GetPrintPreviewDataForIndex( |
| 67 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, | 67 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, |
| 68 &data); | 68 &data); |
| 69 EXPECT_EQ(NULL, data.get()); | 69 EXPECT_EQ(NULL, data.get()); |
| 70 | 70 |
| 71 std::vector<unsigned char> preview_data(blob1, blob1 + sizeof(blob1)); | 71 std::vector<unsigned char> preview_data(blob1, blob1 + sizeof(blob1)); |
| 72 scoped_refptr<RefCountedBytes> dummy_data(new RefCountedBytes(preview_data)); | 72 scoped_refptr<RefCountedBytes> dummy_data(new RefCountedBytes(preview_data)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ASSERT_TRUE(controller); | 105 ASSERT_TRUE(controller); |
| 106 | 106 |
| 107 initiator_tab->print_view_manager()->PrintPreviewNow(); | 107 initiator_tab->print_view_manager()->PrintPreviewNow(); |
| 108 TabContentsWrapper* preview_tab = | 108 TabContentsWrapper* preview_tab = |
| 109 controller->GetOrCreatePreviewTab(initiator_tab); | 109 controller->GetOrCreatePreviewTab(initiator_tab); |
| 110 | 110 |
| 111 EXPECT_NE(initiator_tab, preview_tab); | 111 EXPECT_NE(initiator_tab, preview_tab); |
| 112 EXPECT_EQ(1, browser()->tab_count()); | 112 EXPECT_EQ(1, browser()->tab_count()); |
| 113 EXPECT_EQ(1U, GetConstrainedWindowCount(initiator_tab)); | 113 EXPECT_EQ(1U, GetConstrainedWindowCount(initiator_tab)); |
| 114 | 114 |
| 115 PrintPreviewUI* preview_ui = reinterpret_cast<PrintPreviewUI*>( | 115 PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>( |
| 116 preview_tab->web_contents()->GetWebUI()); | 116 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 117 ASSERT_TRUE(preview_ui != NULL); | 117 ASSERT_TRUE(preview_ui != NULL); |
| 118 | 118 |
| 119 scoped_refptr<RefCountedBytes> data; | 119 scoped_refptr<RefCountedBytes> data; |
| 120 preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, &data); | 120 preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, &data); |
| 121 EXPECT_EQ(NULL, data.get()); | 121 EXPECT_EQ(NULL, data.get()); |
| 122 | 122 |
| 123 std::vector<unsigned char> preview_data(blob1, blob1 + sizeof(blob1)); | 123 std::vector<unsigned char> preview_data(blob1, blob1 + sizeof(blob1)); |
| 124 scoped_refptr<RefCountedBytes> dummy_data(new RefCountedBytes(preview_data)); | 124 scoped_refptr<RefCountedBytes> dummy_data(new RefCountedBytes(preview_data)); |
| 125 | 125 |
| 126 preview_ui->SetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, | 126 preview_ui->SetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 ASSERT_TRUE(controller); | 166 ASSERT_TRUE(controller); |
| 167 | 167 |
| 168 initiator_tab->print_view_manager()->PrintPreviewNow(); | 168 initiator_tab->print_view_manager()->PrintPreviewNow(); |
| 169 TabContentsWrapper* preview_tab = | 169 TabContentsWrapper* preview_tab = |
| 170 controller->GetOrCreatePreviewTab(initiator_tab); | 170 controller->GetOrCreatePreviewTab(initiator_tab); |
| 171 | 171 |
| 172 EXPECT_NE(initiator_tab, preview_tab); | 172 EXPECT_NE(initiator_tab, preview_tab); |
| 173 EXPECT_EQ(1, browser()->tab_count()); | 173 EXPECT_EQ(1, browser()->tab_count()); |
| 174 EXPECT_EQ(1U, GetConstrainedWindowCount(initiator_tab)); | 174 EXPECT_EQ(1U, GetConstrainedWindowCount(initiator_tab)); |
| 175 | 175 |
| 176 PrintPreviewUI* preview_ui = reinterpret_cast<PrintPreviewUI*>( | 176 PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>( |
| 177 preview_tab->web_contents()->GetWebUI()); | 177 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 178 ASSERT_TRUE(preview_ui != NULL); | 178 ASSERT_TRUE(preview_ui != NULL); |
| 179 | 179 |
| 180 // Test with invalid |preview_ui_addr|. | 180 // Test with invalid |preview_ui_addr|. |
| 181 bool cancel = false; | 181 bool cancel = false; |
| 182 preview_ui->GetCurrentPrintPreviewStatus("invalid", 0, &cancel); | 182 preview_ui->GetCurrentPrintPreviewStatus("invalid", 0, &cancel); |
| 183 EXPECT_TRUE(cancel); | 183 EXPECT_TRUE(cancel); |
| 184 | 184 |
| 185 const int kFirstRequestId = 1000; | 185 const int kFirstRequestId = 1000; |
| 186 const int kSecondRequestId = 1001; | 186 const int kSecondRequestId = 1001; |
| 187 const std::string preview_ui_addr = preview_ui->GetPrintPreviewUIAddress(); | 187 const std::string preview_ui_addr = preview_ui->GetPrintPreviewUIAddress(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 203 cancel = false; | 203 cancel = false; |
| 204 preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kFirstRequestId, | 204 preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kFirstRequestId, |
| 205 &cancel); | 205 &cancel); |
| 206 EXPECT_TRUE(cancel); | 206 EXPECT_TRUE(cancel); |
| 207 | 207 |
| 208 cancel = true; | 208 cancel = true; |
| 209 preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kSecondRequestId, | 209 preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kSecondRequestId, |
| 210 &cancel); | 210 &cancel); |
| 211 EXPECT_FALSE(cancel); | 211 EXPECT_FALSE(cancel); |
| 212 } | 212 } |
| OLD | NEW |