~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to test/xaml/test-toplevel-canvas-events.html

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
2
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
3
<head>
 
4
        <title>Test file</title>
 
5
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
 
6
        <script src="../js/js/utils.js"></script>
 
7
        <script src="../js/js/testplugin.js"></script>
 
8
</head>
 
9
<body>
 
10
 
 
11
<script type="text/xaml" id="xaml0">
 
12
        <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 
13
                Name="C0" Height="800" Width="800" Background="Green" >
 
14
        </Canvas>
 
15
</script>
 
16
 
 
17
<script type="text/xaml" id="xaml1">
 
18
        <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 
19
                Name="C1" Height="800" Width="800" Background="Green" 
 
20
                GotFocus="OnGotFocus" LostFocus="OnLostFocus" KeyDown="OnKeyDown" KeyUp="OnKeyUp" >
 
21
        </Canvas>
 
22
</script>
 
23
 
 
24
<script type="text/xaml" id="xaml2">
 
25
        <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 
26
                Name="C2" Height="800" Width="800" Background="Red" >   
 
27
                <Canvas GotFocus="Dummy" />
 
28
        </Canvas>
 
29
</script>
 
30
 
 
31
<script type="text/xaml" id="xaml3">
 
32
        <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 
33
                Name="C3" Height="800" Width="800" Background="Red" >   
 
34
                <Canvas LostFocus="Dummy" />
 
35
        </Canvas>
 
36
</script>
 
37
 
 
38
<script type="text/xaml" id="xaml4">
 
39
        <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 
40
                Name="C4" Height="800" Width="800" Background="Red" >   
 
41
                <Canvas KeyDown="Dummy" />
 
42
        </Canvas>
 
43
</script>
 
44
 
 
45
<script type="text/xaml" id="xaml5">
 
46
        <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 
47
                Name="C5" Height="800" Width="800" Background="Red" >   
 
48
                <Canvas KeyUp="Dummy" />
 
49
        </Canvas>
 
50
</script>
 
51
 
 
52
<script type="text/javascript">
 
53
 
 
54
        // 
 
55
        // It's only possible to attach event handlers for GotFocus, LostFocus, KeyUp and KeyDown on the root canvas.
 
56
        // 
 
57
        var failed = false;
 
58
        var index = -1;
 
59
        var xamls = [
 
60
                '<Canvas GotFocus="Dummy" />', 
 
61
                '<Canvas LostFocus="Dummy" />',
 
62
                '<Canvas KeyDown="Dummy" />',
 
63
                '<Canvas KeyUp="Dummy" />'
 
64
                ];
 
65
        var embeds = [
 
66
                '<embed type="application/x-silverlight" width="20" height="20" id="TF0" Source="#xaml0" OnError="OnPluginError" OnLoad="OnPluginLoaded" background="Red"></embed>',
 
67
                '<embed type="application/x-silverlight" width="20" height="20" id="TF1" Source="#xaml1" OnError="OnPluginError" OnLoad="OnPluginLoaded" background="Red"></embed>',
 
68
                '<embed type="application/x-silverlight" width="20" height="20" id="TF2" Source="#xaml2" OnError="OnPluginError" OnLoad="OnPluginLoaded" background="Green"></embed>',
 
69
                '<embed type="application/x-silverlight" width="20" height="20" id="TF3" Source="#xaml3" OnError="OnPluginError" OnLoad="OnPluginLoaded" background="Green"></embed>',
 
70
                '<embed type="application/x-silverlight" width="20" height="20" id="TF2" Source="#xaml4" OnError="OnPluginError" OnLoad="OnPluginLoaded" background="Green"></embed>',
 
71
                '<embed type="application/x-silverlight" width="20" height="20" id="TF3" Source="#xaml5" OnError="OnPluginError" OnLoad="OnPluginLoaded" background="Green"></embed>'
 
72
                        ];
 
73
        var results = [
 
74
                true, true, false, false, false, false
 
75
                ];
 
76
 
 
77
        function DoCreateXamlTests ()
 
78
        {
 
79
                var plugin = document.getElementById ("TF0");
 
80
                var top = plugin.content.findName ("C0");
 
81
                var obj;
 
82
 
 
83
                TestLogger.LogDebug ("DoCreateXamlFragments, trying to load " + xamls.length + " fragments");
 
84
 
 
85
                for (var i = 0; i < xamls.length; i++) {
 
86
                        try {
 
87
                                var f = false;
 
88
                                try {
 
89
                                        obj = plugin.content.createFromXaml (xamls [i]);
 
90
                                } catch (e) {
 
91
                                        f = true;
 
92
                                        TestLogger.LogError ("Couldn't create xaml fragment #" + i + ": " + e);
 
93
                                }
 
94
                                if (!f) {
 
95
                                        top.Children.Add (obj);
 
96
                                        failed = true;
 
97
                                        TestLogger.LogError ("Was able to add xaml fragment #" + i + " to top level canvas, this should have caused an exception.");
 
98
                                }
 
99
                                failed = f;
 
100
                        } catch (e) {
 
101
                                TestLogger.LogDebug ("Exception (as expected) while adding xaml fragment: " + e);
 
102
                        }
 
103
                }
 
104
        }
 
105
 
 
106
        function NextTest ()
 
107
        {
 
108
                index++;
 
109
                if (index >= embeds.length) {
 
110
                        TestLogger.LogResult (failed ? -1 : 1);
 
111
                        SignalShutdown ();
 
112
                        return;
 
113
                }
 
114
 
 
115
                document.getElementById ("testdiv" + index).innerHTML = embeds [index];
 
116
        }       
 
117
        
 
118
 
 
119
        function OnPluginError (sender, args)
 
120
        {
 
121
                TestLogger.LogDebug ("OnPluginError: " + ErrorEventArgsToOneLineString (args));
 
122
                if (results [index]) {
 
123
                        failed = true;
 
124
                        TestLogger.LogError ("Xaml #" + index + " should not fail.");
 
125
                }
 
126
                NextTest ();
 
127
        }
 
128
        
 
129
        function OnPluginLoaded (sender, args)
 
130
        {
 
131
                TestLogger.LogDebug ("OnPluginLoaded: " + sender);
 
132
                if (!results [index]) {
 
133
                        failed = true;
 
134
                        TestLogger.LogError ("Xaml #" + index + " should fail.");
 
135
                } else {
 
136
                        if (index == 0)
 
137
                                DoCreateXamlTests ();
 
138
                }
 
139
                NextTest ();
 
140
        }
 
141
 
 
142
        function Dummy () {}
 
143
 
 
144
        setTimeout (NextTest, 500);
 
145
</script>
 
146
 
 
147
<div id="testdiv0"></div><div style="height:2px"></div>
 
148
<div id="testdiv1"></div><div style="height:2px"></div>
 
149
<div id="testdiv2"></div><div style="height:2px"></div>
 
150
<div id="testdiv3"></div><div style="height:2px"></div>
 
151
<div id="testdiv4"></div><div style="height:2px"></div>
 
152
<div id="testdiv5"></div><div style="height:2px"></div>
 
153
 
 
154
</div>
 
155
 
 
156
<!--
 
157
<embed id="_TestPlugin" width="0" height="0" type="application/x-jolttest" 
 
158
>
 
159
</embed>
 
160
-->
 
161
 
 
162
</body>
 
163
</html>