~ubuntu-branches/ubuntu/saucy/gnome-shell/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/interactive/background-size.js

Tags: upstream-3.3.90
Import upstream version 3.3.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
2
 
 
3
const Clutter = imports.gi.Clutter;
 
4
const St = imports.gi.St;
 
5
 
 
6
const UI = imports.testcommon.ui;
 
7
 
 
8
UI.init();
 
9
let stage = Clutter.Stage.get_default();
 
10
stage.width = 1024;
 
11
stage.height = 768;
 
12
 
 
13
let vbox = new St.BoxLayout({ width: stage.width,
 
14
                              height: stage.height,
 
15
                              style: 'background: #ffee88;' });
 
16
stage.add_actor(vbox);
 
17
 
 
18
let scroll = new St.ScrollView();
 
19
vbox.add(scroll, { expand: true });
 
20
 
 
21
let vbox = new St.BoxLayout({ vertical: true,
 
22
                              style: 'padding: 10px;'
 
23
                                     + 'spacing: 20px;' });
 
24
scroll.add_actor(vbox);
 
25
 
 
26
let tbox = null;
 
27
 
 
28
function addTestCase(image, size, backgroundSize) {
 
29
    let obin = new St.Bin({ style: 'border: 3px solid green;' });
 
30
    tbox.add(obin);
 
31
 
 
32
    let bin = new St.Bin({ style_class: 'background-image-' + image,
 
33
                           width: size.width,
 
34
                           height: size.height,
 
35
                           style: 'border: 1px solid transparent;'
 
36
                                  + 'background-size: ' + backgroundSize + ';',
 
37
                           x_fill: true,
 
38
                           y_fill: true
 
39
                         });
 
40
    obin.set_child(bin);
 
41
 
 
42
    bin.set_child(new St.Label({ text: backgroundSize,
 
43
                                 style: 'font-size: 15px;'
 
44
                                        + 'text-align: center;'
 
45
                               }));
 
46
}
 
47
 
 
48
function addTestLine(image, size, backgroundSizes) {
 
49
    vbox.add(new St.Label({ text: image + '.svg / ' + size.width + '×' + size.height,
 
50
                            style: 'font-size: 15px;'
 
51
                                   + 'text-align: center;'
 
52
                          }));
 
53
 
 
54
    tbox = new St.BoxLayout({ style: 'spacing: 20px;' });
 
55
    vbox.add(tbox);
 
56
 
 
57
    if (backgroundSizes.length == 2)
 
58
        addTestCase(image, size, "auto");
 
59
    for each (let s in backgroundSizes)
 
60
        addTestCase(image, size, s);
 
61
}
 
62
 
 
63
let size1 = { width: 200, height: 200 }
 
64
let size2 = { width: 250, height: 250 }
 
65
let size3 = { width: 100, height: 100 }
 
66
 
 
67
// fixed size
 
68
addTestLine('200-200', size1, ["200px 200px", "100px 100px", "100px 200px"]);
 
69
 
 
70
// same size
 
71
addTestLine('200-200', size1, ["contain", "cover"]);
 
72
// smaller
 
73
addTestLine('200-200', size2, ["contain", "cover"]);
 
74
// larger
 
75
addTestLine('200-200', size3, ["contain", "cover"]);
 
76
 
 
77
 
 
78
addTestLine('200-100', size1, ["contain", "cover"]);
 
79
addTestLine('200-100', size2, ["contain", "cover"]);
 
80
addTestLine('200-100', size3, ["contain", "cover"]);
 
81
 
 
82
 
 
83
addTestLine('100-200', size1, ["contain", "cover"]);
 
84
addTestLine('100-200', size2, ["contain", "cover"]);
 
85
addTestLine('100-200', size3, ["contain", "cover"]);
 
86
 
 
87
stage.show();
 
88
Clutter.main();
 
89
stage.destroy();