summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/webui/print_preview.js
blob: beb1c14fa99de9994995b9de3285b0514197c330 (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
84
85
86
// Copyright (c) 2011 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.

(function() {
   function MockHandler() {
     this.__proto__ = MockHandler.prototype;
   };

   MockHandler.prototype = {
     'getDefaultPrinter': function() {
       console.log('getDefaultPrinter');
       setDefaultPrinter('FooDevice');
     },
     'getPrinters': function() {
       console.log('getPrinters');
       setPrinters([
                     {
                       'printerName': 'FooName',
                       'deviceName': 'FooDevice',
                     },
                     {
                       'printerName': 'BarName',
                       'deviceName': 'BarDevice',
                     },
                   ]);
     },
     'getPreview': function(settings) {
       console.log('getPreview(' + settings + ')');
       updatePrintPreview(1, 'title', true);
     },
     'print': function(settings) {
       console.log('print(' + settings + ')');
     },
     'getPrinterCapabilities': function(printer_name) {
       console.log('getPrinterCapabilities(' + printer_name + ')');
       updateWithPrinterCapabilities({
                                       'disableColorOption': true,
                                       'setColorAsDefault': true,
                                       'disableCopiesOption': true
                                     });
     },
     'showSystemDialog': function() {
       console.log('showSystemDialog');
     },
     'managePrinters': function() {
       console.log('managePrinters');
     },
     'closePrintPreviewTab': function() {
       console.log('closePrintPreviewTab');
     },
     'hidePreview': function() {
       console.log('hidePreview');
     },
   };

   function registerCallbacks() {
     console.log('registeringCallbacks');
     var mock_handler = new MockHandler();
     for (func in MockHandler.prototype) {
       if (typeof(mock_handler[func]) == 'function')
         registerMessageCallback(func,
                                 mock_handler,
                                 mock_handler[func]);
     }
   };

   if ('window' in this && 'registerMessageCallback' in window)
     registerCallbacks();
 })();

// Tests.
function FLAKY_TestPrinterList() {
  var printer_list = $('printer-list');
  assertTrue(!!printer_list, 'printer_list');
  assertTrue(printer_list.options.length >= 2, 'printer-list has at least 2');
  expectEquals('FooName', printer_list.options[0].text, '0 text is FooName');
  expectEquals('FooDevice', printer_list.options[0].value,
               '0 value is FooDevice');
  expectEquals('BarName', printer_list.options[1].text, '1 text is BarName');
  expectEquals('BarDevice', printer_list.options[1].value,
               '1 value is BarDevice');
}

var test_fixture = 'PrintPreviewWebUITest';
var test_add_library = false;