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

« back to all changes in this revision

Viewing changes to test/xaml/assorted/namescope-corner-cases.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
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 
2
<head>
 
3
<title>NameScope test</title>
 
4
<meta></meta>
 
5
</head>
 
6
<body>
 
7
 
 
8
<script type="text/javascript">
 
9
var control = null;
 
10
var content = null;
 
11
var logger = null;
 
12
 
 
13
function Log (color, text)
 
14
{
 
15
  var run = content.createFromXaml ("<Run Foreground='" + color + "'/>");
 
16
  var eoln = content.createFromXaml ("<LineBreak/>");
 
17
 
 
18
  run.text = text;
 
19
  logger.inlines.add (run);
 
20
  logger.inlines.add (eoln);
 
21
}
 
22
 
 
23
function test1 ()
 
24
{
 
25
  // see what happens when a named brush is set as a property
 
26
  // on multiple elements in the same NameScope.
 
27
 
 
28
  var tree0 = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Canvas.Top='5' Canvas.Left='5' x:Name='Tree0'><Rectangle x:Name='Rect0' Canvas.Left='0' Width='10' Height='10'><Rectangle.Stroke><SolidColorBrush x:Name='MyBrush' Color='Green'/></Rectangle.Stroke></Rectangle><Rectangle x:Name='Rect1' Canvas.Left='15' Width='10' Height='10'/></Canvas>", true);
 
29
 
 
30
  var rect = tree0.findName ("Rect0");
 
31
  var brush = rect.stroke;
 
32
 
 
33
  rect = tree0.findName ("Rect1");
 
34
  rect.fill = brush;
 
35
 
 
36
  var res = tree0.findName ("MyBrush");
 
37
  if (res != brush)
 
38
    Log ("green", "FindName() correctly did not find the re-used brush in the same namescope.");
 
39
  else
 
40
    Log ("red", "FindName() incorrectly found the re-used brush in the same namescope.");
 
41
}
 
42
 
 
43
function test2 ()
 
44
{
 
45
  // see if we can re-use the same brush in a second namespace
 
46
  // and whether or not FindName() will find it in both places.
 
47
  var tree0 = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Canvas.Top='5' Canvas.Left='5' x:Name='Tree0'><Rectangle x:Name='Rect0' Canvas.Left='0' Width='10' Height='10'><Rectangle.Stroke><SolidColorBrush x:Name='MyBrush' Color='Green'/></Rectangle.Stroke></Rectangle><Rectangle x:Name='Rect1' Canvas.Left='15' Width='10' Height='10'/></Canvas>", true);
 
48
 
 
49
  var tree1 = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Canvas.Top='5' Canvas.Left='35' x:Name='Tree1'><Rectangle x:Name='Rect2' Canvas.Left='0' Width='10' Height='10'/><Rectangle x:Name='Rect3' Canvas.Left='15' Width='10' Height='10'/></Canvas>", true);
 
50
 
 
51
  var rect = tree0.findName ("Rect0");
 
52
  var brush = rect.stroke;
 
53
 
 
54
  rect = tree1.findName ("Rect2");
 
55
  rect.stroke = brush;
 
56
 
 
57
  rect = tree1.findName ("Rect3");
 
58
  rect.fill = brush;
 
59
 
 
60
  res = tree1.findName ("MyBrush");
 
61
  if (res != brush)
 
62
    Log ("green", "FindName() correctly did not find the re-used brush in the alternate namescope.");
 
63
  else
 
64
    Log ("red", "FindName() incorrectly found the re-used brush in the alternate namescope.");
 
65
}
 
66
 
 
67
function test3 ()
 
68
{
 
69
  // see if names conflict if added from a separate subtree (which has a temp scope)
 
70
 
 
71
  var tree2 = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Canvas.Top='5' Canvas.Left='35' x:Name='Tree1'><Rectangle x:Name='Rect2' Canvas.Left='0' Width='10' Height='10'/><Rectangle x:Name='Rect3' Canvas.Left='15' Width='10' Height='10'/></Canvas>", true);
 
72
  var tree3 = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Canvas.Top='5' Canvas.Left='35' x:Name='Tree2'><Rectangle x:Name='Rect2'/></Canvas>");
 
73
 
 
74
  var exception = null;
 
75
  try {
 
76
    tree2.children.add (tree3);
 
77
  }
 
78
  catch (ex) {
 
79
    exception = ex;
 
80
  }
 
81
 
 
82
  if (exception != null)
 
83
    Log ("green", "merging namescopes with conflicting names did generate error");
 
84
  else
 
85
    Log ("red", "merging namescopes with conflicting names did not generate error");
 
86
 
 
87
  var conflicting = tree3.findName ("Rect2");
 
88
  if (conflicting)
 
89
    Log ("red", "after merge failed due to exception, Rect2 was still findName()able in child tree");
 
90
  else
 
91
    Log ("green", "after merge failed due to exception, Rect2 was not findName()able in child tree");
 
92
 
 
93
  var original = tree2.findName ("Rect2");
 
94
  if (original)
 
95
    Log ("green", "after merge failed due to exception, Rect2 was still findName()able in original tree");
 
96
  else
 
97
    Log ("red", "after merge failed due to exception, Rect2 was not findName()able in original tree");
 
98
 
 
99
}
 
100
 
 
101
function test4 ()
 
102
{
 
103
  // see if names in conflict in the same xaml block generate an error (a child element)
 
104
 
 
105
  exception = null;
 
106
  try {
 
107
    var tree4 = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Canvas.Top='5' Canvas.Left='35' x:Name='Tree1'><Rectangle x:Name='Tree1'/></Canvas>");
 
108
  }
 
109
  catch (ex) {
 
110
    exception = ex;
 
111
  }
 
112
 
 
113
  if (exception != null)
 
114
    Log ("green", "two elements with the same name in the same xaml block did generate an error");
 
115
  else
 
116
    Log ("red", "two elements with the same name in the same xaml block did not generate an error");
 
117
}
 
118
 
 
119
function test5 ()
 
120
{
 
121
  // see if names in conflict in the same xaml block generate an error (a property element)
 
122
 
 
123
  exception = null;
 
124
  try {
 
125
    var tree4 = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Canvas.Top='5' Canvas.Left='35' x:Name='Tree1'><Canvas.Clip><RectangleGeometry x:Name='Tree1'/></Canvas.Clip></Canvas>");
 
126
  }
 
127
  catch (ex) {
 
128
    exception = ex;
 
129
  }
 
130
 
 
131
  if (exception != null)
 
132
    Log ("green", "two elements with the same name (property element) in the same xaml block did generate an error");
 
133
  else
 
134
    Log ("red", "two elements with the same name (property element) in the same xaml block did not generate an error");
 
135
}
 
136
 
 
137
function test6 ()
 
138
{
 
139
  // see if we can remove a child then re-add it and have the name be available
 
140
 
 
141
  var tree5 = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Tree2'><Canvas x:Name='Subtree'><Rectangle x:Name='Rect2'/></Canvas></Canvas>");
 
142
 
 
143
  var child = tree5.children.getItem(0);
 
144
  tree5.children.clear ();
 
145
 
 
146
  tree5.printf ("before children.add");
 
147
  tree5.children.add (child);
 
148
  tree5.printf ("after children.add");
 
149
 
 
150
//  if (tree5.findName ("Subtree") != null)
 
151
//    Log ("green", "child is once again findName()able after being removed and re-added");
 
152
//  else
 
153
//    Log ("red", "child is not findName()able after being removed and re-added");
 
154
 
 
155
  if (tree5.findName ("Rect2") != null)
 
156
    Log ("green", "descendent is once again findName()able after being removed and re-added");
 
157
  else
 
158
    Log ("red", "descendent is not findName()able after being removed and re-added");
 
159
}
 
160
 
 
161
function test7 ()
 
162
{
 
163
  // see if we can remove a child then re-add it and have the name be available
 
164
 
 
165
  var tree5 = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Tree2'><Canvas x:Name='Subtree'><Rectangle x:Name='Rect2'/></Canvas></Canvas>");
 
166
 
 
167
  var child = tree5.children.getItem(0);
 
168
  tree5.children.clear ();
 
169
 
 
170
  if (child.findName ("Subtree") == null)
 
171
    Log ("green", "Subtree cannot be looked up in disconnected subtree");
 
172
  else
 
173
    Log ("red", "Subtree can be looked up in disconnected subtree");
 
174
 
 
175
  if (child.findName ("Rect2") == null)
 
176
    Log ("green", "Rect2 cannot be looked up in disconnected subtree");
 
177
  else
 
178
    Log ("red", "Rect2 can be looked up in disconnected subtree");
 
179
 
 
180
  tree5.children.add (child);
 
181
 
 
182
  if (tree5.findName ("Subtree") != null)
 
183
    Log ("green", "child is once again findName()able after being removed and re-added");
 
184
  else
 
185
    Log ("red", "child is not findName()able after being removed and re-added");
 
186
 
 
187
  if (tree5.findName ("Rect2") != null)
 
188
    Log ("green", "descendent is once again findName()able after being removed and re-added");
 
189
  else
 
190
    Log ("red", "descendent is not findName()able after being removed and re-added");
 
191
}
 
192
 
 
193
function test8 ()
 
194
{
 
195
  // see if a temp namescope causes children to no longer be
 
196
  // findName()able if we remove the subtree from the hierarchy and
 
197
  // add it back
 
198
 
 
199
  var tree = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Tree'/>");
 
200
  var subtree = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Subtree'><Rectangle x:Name='Rect2'/></Canvas>");
 
201
 
 
202
  tree.children.add (subtree);
 
203
 
 
204
  if (tree.findName ("Subtree") != null)
 
205
    Log ("green", "child is locatable after adding to hierarchy");
 
206
  else
 
207
    Log ("red", "child is not locatable after adding to hierarchy");
 
208
 
 
209
  tree.children.clear ();
 
210
 
 
211
  if (subtree.findName ("Subtree") == null)
 
212
    Log ("green", "Subtree cannot be looked up in disconnected subtree");
 
213
  else
 
214
    Log ("red", "Subtree can be looked up in disconnected subtree");
 
215
 
 
216
  if (subtree.findName ("Rect2") == null)
 
217
    Log ("green", "Rect2 cannot be looked up in disconnected subtree");
 
218
  else
 
219
    Log ("red", "Rect2 can be looked up in disconnected subtree");
 
220
 
 
221
  tree.children.add (subtree);
 
222
 
 
223
  if (tree.findName ("Rect2") != null)
 
224
    Log ("green", "descendent is once again findName()able after being removed and re-added");
 
225
  else
 
226
    Log ("red", "descendent is not findName()able after being removed and re-added");
 
227
 
 
228
}
 
229
 
 
230
function test9 ()
 
231
{
 
232
  // we create a temp namescope on a subtree, add the subtree to
 
233
  // the main tree, then remove it. then we add a new name to it
 
234
  // and see if we can look up the new name on the subtree.  then
 
235
  // we add it back to the main tree and look up the name there.
 
236
 
 
237
  var tree = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Tree'/>");
 
238
  var subtree = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Subtree'><Rectangle x:Name='Rect2'/></Canvas>");
 
239
 
 
240
  tree.children.add (subtree);
 
241
 
 
242
  tree.children.clear ();
 
243
 
 
244
  var new_child = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Subtree2' />");
 
245
 
 
246
  subtree.children.add (new_child);
 
247
 
 
248
  if (subtree.findName ("Subtree2") == null)
 
249
    Log ("green", "Subtree2 cannot be looked up in disconnected subtree");
 
250
  else
 
251
    Log ("red", "Subtree2 can be looked up in disconnected subtree");
 
252
 
 
253
  tree.children.add (subtree);
 
254
 
 
255
  if (tree.findName ("Subtree2") != null)
 
256
    Log ("green", "Subtree2 can be looked up once the subtree is reconnected");
 
257
  else
 
258
    Log ("red", "Subtree2 cannot be looked up once the subtree is reconnected");
 
259
}
 
260
 
 
261
function test10 ()
 
262
{
 
263
  // we create a temp namescope on a subtree, add the subtree to the
 
264
  // main tree, then remove it (to kill its namescope).  then we add a
 
265
  // conflicting named child to it and see if that flags an error.
 
266
 
 
267
  var tree = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Tree'/>");
 
268
  var subtree = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Subtree'><Rectangle x:Name='Rect2'/></Canvas>");
 
269
 
 
270
  tree.children.add (subtree);
 
271
 
 
272
  tree.children.clear ();
 
273
 
 
274
  var new_child = content.createFromXaml ("<Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='Subtree' />");
 
275
 
 
276
  var exception = null;
 
277
  try {
 
278
    subtree.children.add (new_child);
 
279
  }
 
280
  catch (ex) {
 
281
    exception = ex;
 
282
  }
 
283
 
 
284
  if (exception != null)
 
285
    Log ("red", "adding conflicting child to subtree without namescope raised exception");
 
286
  else
 
287
    Log ("green", "adding conflicting child to subtree without namescope didn't raise exception");
 
288
 
 
289
  exception = null;
 
290
  try {
 
291
    tree.children.add (subtree);
 
292
  }
 
293
  catch (ex) {
 
294
    exception = ex;
 
295
  }
 
296
 
 
297
  if (exception != null)
 
298
    Log ("green", "adding subtree with conflicting child name back to root tree raised exception");
 
299
  else
 
300
    Log ("red", "adding subtree with conflicting child name back to root tree didn't raise exception");
 
301
}
 
302
 
 
303
function OnLoaded (sender, eventArgs)
 
304
{
 
305
  control = document.getElementById ("agControl");
 
306
  content = control.content;
 
307
 
 
308
  logger = sender.findName ("Log");
 
309
 
 
310
  Log ("black", "test1");
 
311
  test1 ();
 
312
  Log ("black", "test2");
 
313
  test2 ();
 
314
  Log ("black", "test3");
 
315
  test3 ();
 
316
  Log ("black", "test4");
 
317
  test4 ();
 
318
  Log ("black", "test5");
 
319
  test5 ();
 
320
  Log ("black", "test6");
 
321
  test6 ();
 
322
  Log ("black", "test7");
 
323
  test7 ();
 
324
  Log ("black", "test8");
 
325
  test8 ();
 
326
  Log ("black", "test9");
 
327
  test9 ();
 
328
  Log ("black", "test10");
 
329
  test10 ();
 
330
}
 
331
</script>
 
332
 
 
333
<object type="application/x-silverlight" data="data:," id="agControl" width="100%" height="100%">
 
334
<param name="background" value="#FFFFFF"/>
 
335
<param name="source" value="#xamlContent"/>
 
336
</object>
 
337
 
 
338
<script type="text/xaml" id="xamlContent">
 
339
<?xml version="1.0"?>
 
340
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 
341
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 
342
        Loaded="OnLoaded">
 
343
  <TextBlock FontSize="10" Canvas.Left="5" Canvas.Top="25" x:Name="Log"/>
 
344
</Canvas>
 
345
</script>
 
346
 
 
347
</body>
 
348
</html>