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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 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
« no previous file with comments | « chrome/browser/printing/print_job.cc ('k') | chrome/browser/printing/print_job_worker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/string16.h" 6 #include "base/string16.h"
7 #include "chrome/browser/printing/print_job.h" 7 #include "chrome/browser/printing/print_job.h"
8 #include "chrome/browser/printing/print_job_worker.h" 8 #include "chrome/browser/printing/print_job_worker.h"
9 #include "chrome/common/chrome_notification_types.h" 9 #include "chrome/common/chrome_notification_types.h"
10 #include "content/public/browser/notification_registrar.h" 10 #include "content/public/browser/notification_registrar.h"
(...skipping 28 matching lines...) Expand all
39 virtual printing::PrintJobWorker* DetachWorker( 39 virtual printing::PrintJobWorker* DetachWorker(
40 printing::PrintJobWorkerOwner* new_owner) OVERRIDE { 40 printing::PrintJobWorkerOwner* new_owner) OVERRIDE {
41 // We're screwing up here since we're calling worker from the main thread. 41 // We're screwing up here since we're calling worker from the main thread.
42 // That's fine for testing. It is actually simulating PrinterQuery behavior. 42 // That's fine for testing. It is actually simulating PrinterQuery behavior.
43 TestPrintJobWorker* worker(new TestPrintJobWorker(new_owner)); 43 TestPrintJobWorker* worker(new TestPrintJobWorker(new_owner));
44 EXPECT_TRUE(worker->Start()); 44 EXPECT_TRUE(worker->Start());
45 worker->printing_context()->UseDefaultSettings(); 45 worker->printing_context()->UseDefaultSettings();
46 settings_ = worker->printing_context()->settings(); 46 settings_ = worker->printing_context()->settings();
47 return worker; 47 return worker;
48 } 48 }
49 virtual MessageLoop* message_loop() OVERRIDE { 49 virtual base::MessageLoop* message_loop() OVERRIDE {
50 EXPECT_FALSE(true); 50 EXPECT_FALSE(true);
51 return NULL; 51 return NULL;
52 } 52 }
53 virtual const printing::PrintSettings& settings() const OVERRIDE { 53 virtual const printing::PrintSettings& settings() const OVERRIDE {
54 return settings_; 54 return settings_;
55 } 55 }
56 virtual int cookie() const OVERRIDE { 56 virtual int cookie() const OVERRIDE {
57 return 42; 57 return 42;
58 } 58 }
59 59
(...skipping 26 matching lines...) Expand all
86 86
87 } // namespace 87 } // namespace
88 88
89 typedef testing::Test PrintJobTest; 89 typedef testing::Test PrintJobTest;
90 90
91 TEST_F(PrintJobTest, SimplePrint) { 91 TEST_F(PrintJobTest, SimplePrint) {
92 // Test the multi-threaded nature of PrintJob to make sure we can use it with 92 // Test the multi-threaded nature of PrintJob to make sure we can use it with
93 // known lifetime. 93 // known lifetime.
94 94
95 // This message loop is actually never run. 95 // This message loop is actually never run.
96 MessageLoop current; 96 base::MessageLoop current;
97 97
98 content::NotificationRegistrar registrar_; 98 content::NotificationRegistrar registrar_;
99 TestPrintNotifObserv observ; 99 TestPrintNotifObserv observ;
100 registrar_.Add(&observ, content::NOTIFICATION_ALL, 100 registrar_.Add(&observ, content::NOTIFICATION_ALL,
101 content::NotificationService::AllSources()); 101 content::NotificationService::AllSources());
102 volatile bool check = false; 102 volatile bool check = false;
103 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check)); 103 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
104 EXPECT_EQ(MessageLoop::current(), job->message_loop()); 104 EXPECT_EQ(base::MessageLoop::current(), job->message_loop());
105 scoped_refptr<TestOwner> owner(new TestOwner); 105 scoped_refptr<TestOwner> owner(new TestOwner);
106 TestSource source; 106 TestSource source;
107 job->Initialize(owner, &source, 1); 107 job->Initialize(owner, &source, 1);
108 job->Stop(); 108 job->Stop();
109 EXPECT_FALSE(job->is_stopped()); 109 EXPECT_FALSE(job->is_stopped());
110 EXPECT_TRUE(job->is_stopping()); 110 EXPECT_TRUE(job->is_stopping());
111 while (!job->is_stopped()) 111 while (!job->is_stopped())
112 { 112 {
113 current.RunUntilIdle(); 113 current.RunUntilIdle();
114 } 114 }
115 EXPECT_TRUE(job->is_stopped()); 115 EXPECT_TRUE(job->is_stopped());
116 EXPECT_FALSE(job->is_stopping()); 116 EXPECT_FALSE(job->is_stopping());
117 job = NULL; 117 job = NULL;
118 EXPECT_TRUE(check); 118 EXPECT_TRUE(check);
119 } 119 }
120 120
121 TEST_F(PrintJobTest, SimplePrintLateInit) { 121 TEST_F(PrintJobTest, SimplePrintLateInit) {
122 volatile bool check = false; 122 volatile bool check = false;
123 MessageLoop current; 123 base::MessageLoop current;
124 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check)); 124 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
125 job = NULL; 125 job = NULL;
126 EXPECT_TRUE(check); 126 EXPECT_TRUE(check);
127 /* TODO(maruel): Test these. 127 /* TODO(maruel): Test these.
128 job->Initialize() 128 job->Initialize()
129 job->Observe(); 129 job->Observe();
130 job->GetSettingsDone(); 130 job->GetSettingsDone();
131 job->DetachWorker(); 131 job->DetachWorker();
132 job->message_loop(); 132 job->message_loop();
133 job->settings(); 133 job->settings();
134 job->cookie(); 134 job->cookie();
135 job->GetSettings(printing::DEFAULTS, printing::ASK_USER, NULL); 135 job->GetSettings(printing::DEFAULTS, printing::ASK_USER, NULL);
136 job->StartPrinting(); 136 job->StartPrinting();
137 job->Stop(); 137 job->Stop();
138 job->Cancel(); 138 job->Cancel();
139 job->RequestMissingPages(); 139 job->RequestMissingPages();
140 job->FlushJob(timeout); 140 job->FlushJob(timeout);
141 job->DisconnectSource(); 141 job->DisconnectSource();
142 job->is_job_pending(); 142 job->is_job_pending();
143 job->document(); 143 job->document();
144 // Private 144 // Private
145 job->UpdatePrintedDocument(NULL); 145 job->UpdatePrintedDocument(NULL);
146 scoped_refptr<printing::JobEventDetails> event_details; 146 scoped_refptr<printing::JobEventDetails> event_details;
147 job->OnNotifyPrintJobEvent(event_details); 147 job->OnNotifyPrintJobEvent(event_details);
148 job->OnDocumentDone(); 148 job->OnDocumentDone();
149 job->ControlledWorkerShutdown(); 149 job->ControlledWorkerShutdown();
150 */ 150 */
151 } 151 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job.cc ('k') | chrome/browser/printing/print_job_worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698