This source file includes following definitions.
- RenderSourceName
- GetSettingsDone
- DetachWorker
- message_loop
- settings
- cookie
- Observe
- TEST_F
- TEST_F
#include "base/message_loop/message_loop.h"
#include "base/strings/string16.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/print_job_worker.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "printing/printed_pages_source.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class TestSource : public printing::PrintedPagesSource {
public:
virtual base::string16 RenderSourceName() OVERRIDE {
return base::string16();
}
};
class TestPrintJobWorker : public printing::PrintJobWorker {
public:
explicit TestPrintJobWorker(printing::PrintJobWorkerOwner* owner)
: printing::PrintJobWorker(owner) {
}
friend class TestOwner;
};
class TestOwner : public printing::PrintJobWorkerOwner {
public:
virtual void GetSettingsDone(
const printing::PrintSettings& new_settings,
printing::PrintingContext::Result result) OVERRIDE {
EXPECT_FALSE(true);
}
virtual printing::PrintJobWorker* DetachWorker(
printing::PrintJobWorkerOwner* new_owner) OVERRIDE {
TestPrintJobWorker* worker(new TestPrintJobWorker(new_owner));
EXPECT_TRUE(worker->Start());
worker->printing_context()->UseDefaultSettings();
settings_ = worker->printing_context()->settings();
return worker;
}
virtual base::MessageLoop* message_loop() OVERRIDE {
EXPECT_FALSE(true);
return NULL;
}
virtual const printing::PrintSettings& settings() const OVERRIDE {
return settings_;
}
virtual int cookie() const OVERRIDE {
return 42;
}
private:
virtual ~TestOwner() {}
printing::PrintSettings settings_;
};
class TestPrintJob : public printing::PrintJob {
public:
explicit TestPrintJob(volatile bool* check) : check_(check) {
}
private:
virtual ~TestPrintJob() {
*check_ = true;
}
volatile bool* check_;
};
class TestPrintNotifObserv : public content::NotificationObserver {
public:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
ADD_FAILURE();
}
};
}
typedef testing::Test PrintJobTest;
TEST_F(PrintJobTest, SimplePrint) {
base::MessageLoop current;
content::NotificationRegistrar registrar_;
TestPrintNotifObserv observ;
registrar_.Add(&observ, content::NOTIFICATION_ALL,
content::NotificationService::AllSources());
volatile bool check = false;
scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
EXPECT_EQ(base::MessageLoop::current(), job->message_loop());
scoped_refptr<TestOwner> owner(new TestOwner);
TestSource source;
job->Initialize(owner.get(), &source, 1);
job->Stop();
while (job->document()) {
current.RunUntilIdle();
}
EXPECT_FALSE(job->document());
job = NULL;
while (!check) {
current.RunUntilIdle();
}
EXPECT_TRUE(check);
}
TEST_F(PrintJobTest, SimplePrintLateInit) {
volatile bool check = false;
base::MessageLoop current;
scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
job = NULL;
EXPECT_TRUE(check);
}