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

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

Issue 478183005: Added PrintingContext::Delegate to get parent view handle and application locale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mon Aug 25 23:50:54 PDT 2014 Created 6 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 "chrome/browser/printing/print_job.h"
6
5 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
6 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
7 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/printing/print_job.h"
9 #include "chrome/browser/printing/print_job_worker.h" 10 #include "chrome/browser/printing/print_job_worker.h"
10 #include "content/public/browser/notification_registrar.h" 11 #include "content/public/browser/notification_registrar.h"
11 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 #include "content/public/common/child_process_host.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "printing/printed_pages_source.h" 15 #include "printing/printed_pages_source.h"
13 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
14 17
15 namespace { 18 namespace {
16 19
17 class TestSource : public printing::PrintedPagesSource { 20 class TestSource : public printing::PrintedPagesSource {
18 public: 21 public:
19 virtual base::string16 RenderSourceName() OVERRIDE { 22 virtual base::string16 RenderSourceName() OVERRIDE {
20 return base::string16(); 23 return base::string16();
21 } 24 }
22 }; 25 };
23 26
24 class TestPrintJobWorker : public printing::PrintJobWorker { 27 class TestPrintJobWorker : public printing::PrintJobWorker {
25 public: 28 public:
26 explicit TestPrintJobWorker(printing::PrintJobWorkerOwner* owner) 29 explicit TestPrintJobWorker(printing::PrintJobWorkerOwner* owner)
27 : printing::PrintJobWorker(owner) { 30 : printing::PrintJobWorker(content::ChildProcessHost::kInvalidUniqueID,
28 } 31 content::ChildProcessHost::kInvalidUniqueID,
32 owner) {}
29 friend class TestOwner; 33 friend class TestOwner;
30 }; 34 };
31 35
32 class TestOwner : public printing::PrintJobWorkerOwner { 36 class TestOwner : public printing::PrintJobWorkerOwner {
33 public: 37 public:
34 virtual void GetSettingsDone( 38 virtual void GetSettingsDone(
35 const printing::PrintSettings& new_settings, 39 const printing::PrintSettings& new_settings,
36 printing::PrintingContext::Result result) OVERRIDE { 40 printing::PrintingContext::Result result) OVERRIDE {
37 EXPECT_FALSE(true); 41 EXPECT_FALSE(true);
38 } 42 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // content::NotificationObserver 79 // content::NotificationObserver
76 virtual void Observe(int type, 80 virtual void Observe(int type,
77 const content::NotificationSource& source, 81 const content::NotificationSource& source,
78 const content::NotificationDetails& details) OVERRIDE { 82 const content::NotificationDetails& details) OVERRIDE {
79 ADD_FAILURE(); 83 ADD_FAILURE();
80 } 84 }
81 }; 85 };
82 86
83 } // namespace 87 } // namespace
84 88
85 typedef testing::Test PrintJobTest; 89 TEST(PrintJobTest, SimplePrint) {
86
87 TEST_F(PrintJobTest, SimplePrint) {
88 // Test the multi-threaded nature of PrintJob to make sure we can use it with 90 // Test the multi-threaded nature of PrintJob to make sure we can use it with
89 // known lifetime. 91 // known lifetime.
90 92
91 // This message loop is actually never run. 93 content::TestBrowserThreadBundle thread_bundle_;
92 base::MessageLoop current;
93
94 content::NotificationRegistrar registrar_; 94 content::NotificationRegistrar registrar_;
95 TestPrintNotifObserv observ; 95 TestPrintNotifObserv observ;
96 registrar_.Add(&observ, content::NOTIFICATION_ALL, 96 registrar_.Add(&observ,
97 content::NOTIFICATION_ALL,
97 content::NotificationService::AllSources()); 98 content::NotificationService::AllSources());
98 volatile bool check = false; 99 volatile bool check = false;
99 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check)); 100 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
100 EXPECT_TRUE(job->RunsTasksOnCurrentThread()); 101 EXPECT_TRUE(job->RunsTasksOnCurrentThread());
101 scoped_refptr<TestOwner> owner(new TestOwner); 102 scoped_refptr<TestOwner> owner(new TestOwner);
102 TestSource source; 103 TestSource source;
103 job->Initialize(owner.get(), &source, 1); 104 job->Initialize(owner.get(), &source, 1);
104 job->Stop(); 105 job->Stop();
105 while (job->document()) { 106 while (job->document()) {
106 current.RunUntilIdle(); 107 base::MessageLoop::current()->RunUntilIdle();
107 } 108 }
108 EXPECT_FALSE(job->document()); 109 EXPECT_FALSE(job->document());
109 job = NULL; 110 job = NULL;
110 while (!check) { 111 while (!check) {
111 current.RunUntilIdle(); 112 base::MessageLoop::current()->RunUntilIdle();
112 } 113 }
113 EXPECT_TRUE(check); 114 EXPECT_TRUE(check);
114 } 115 }
115 116
116 TEST_F(PrintJobTest, SimplePrintLateInit) { 117 TEST(PrintJobTest, SimplePrintLateInit) {
117 volatile bool check = false; 118 volatile bool check = false;
118 base::MessageLoop current; 119 base::MessageLoop current;
119 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check)); 120 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
120 job = NULL; 121 job = NULL;
121 EXPECT_TRUE(check); 122 EXPECT_TRUE(check);
122 /* TODO(maruel): Test these. 123 /* TODO(maruel): Test these.
123 job->Initialize() 124 job->Initialize()
124 job->Observe(); 125 job->Observe();
125 job->GetSettingsDone(); 126 job->GetSettingsDone();
126 job->DetachWorker(); 127 job->DetachWorker();
(...skipping 10 matching lines...) Expand all
137 job->is_job_pending(); 138 job->is_job_pending();
138 job->document(); 139 job->document();
139 // Private 140 // Private
140 job->UpdatePrintedDocument(NULL); 141 job->UpdatePrintedDocument(NULL);
141 scoped_refptr<printing::JobEventDetails> event_details; 142 scoped_refptr<printing::JobEventDetails> event_details;
142 job->OnNotifyPrintJobEvent(event_details); 143 job->OnNotifyPrintJobEvent(event_details);
143 job->OnDocumentDone(); 144 job->OnDocumentDone();
144 job->ControlledWorkerShutdown(); 145 job->ControlledWorkerShutdown();
145 */ 146 */
146 } 147 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job_manager.cc ('k') | chrome/browser/printing/print_job_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698