summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_printing.cc
blob: 64ce0cea25d95131df372d977b6f36acd778b4c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/tests/test_printing.h"

#include "ppapi/cpp/dev/printing_dev.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/tests/testing_instance.h"

namespace {
bool g_callback_triggered;
int32_t g_callback_result;
PP_PrintSettings_Dev g_print_settings;
}  // namespace

REGISTER_TEST_CASE(Printing);

class TestPrinting_Dev : public pp::Printing_Dev {
 public:
  explicit TestPrinting_Dev(pp::Instance* instance) :
  pp::Printing_Dev(instance) {}
  virtual ~TestPrinting_Dev() {}
  virtual uint32_t QuerySupportedPrintOutputFormats() { return 0; }
  virtual int32_t PrintBegin(
      const PP_PrintSettings_Dev& print_settings) { return 0; }
  virtual pp::Resource PrintPages(
      const PP_PrintPageNumberRange_Dev* page_ranges,
  uint32_t page_range_count) {
    return pp::Resource();
  }
  virtual void PrintEnd() {}
  virtual bool IsPrintScalingDisabled() { return false; }
};

TestPrinting::TestPrinting(TestingInstance* instance)
    : TestCase(instance),
      nested_event_(instance->pp_instance()) {
  callback_factory_.Initialize(this);
}

void TestPrinting::RunTests(const std::string& filter) {
  RUN_TEST(GetDefaultPrintSettings, filter);
}

std::string TestPrinting::TestGetDefaultPrintSettings() {
  g_callback_triggered = false;
  TestPrinting_Dev test_printing(instance_);
  pp::CompletionCallbackWithOutput<PP_PrintSettings_Dev> cb =
      callback_factory_.NewCallbackWithOutput(&TestPrinting::Callback);
  test_printing.GetDefaultPrintSettings(cb);
  nested_event_.Wait();

  ASSERT_EQ(PP_OK, g_callback_result);
  ASSERT_TRUE(g_callback_triggered);

  // Sanity check the |printable_area|, |content_area| and |paper_size| members.
  // It is possible these values are outside these ranges but it shouldn't
  // happen in practice and probably means there is an error in computing
  // the default print settings. These values are in points.
  ASSERT_TRUE(g_print_settings.printable_area.point.x < 200);
  ASSERT_TRUE(g_print_settings.printable_area.point.y < 200);
  ASSERT_TRUE(g_print_settings.printable_area.size.width < 2000);
  ASSERT_TRUE(g_print_settings.printable_area.size.height < 2000);

  ASSERT_TRUE(g_print_settings.content_area.point.x < 200);
  ASSERT_TRUE(g_print_settings.content_area.point.y < 200);
  ASSERT_TRUE(g_print_settings.content_area.size.width < 2000);
  ASSERT_TRUE(g_print_settings.content_area.size.height< 2000);

  ASSERT_TRUE(g_print_settings.paper_size.width < 2000);
  ASSERT_TRUE(g_print_settings.paper_size.height < 2000);

  PASS();
}

void TestPrinting::Callback(int32_t result,
                            PP_PrintSettings_Dev& print_settings) {
  g_callback_triggered = true;
  g_callback_result = result;
  g_print_settings = print_settings;
  nested_event_.Signal();
}