Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: experimental/conways_life/controllers/viewcontroller_test.html

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright (c) 2010 The Ginsu Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
7 -->
8 <head>
9 <title>Ginsu ViewController Tests</title>
10 <link rel="stylesheet" type="text/css" href="jsunit/css/jsUnitStyle.css">
11 <link rel="stylesheet" type="text/css" href="css/ginsu.css"/>
12 <script src="closure/closure/goog/base.js"></script>
13 <script src="jsunit/app/jsUnitCore.js"></script>
14 <script type="text/javascript">
15 goog.require('goog.dom');
16 goog.require('goog.math');
17 goog.require('goog.events.EventTarget');
18 goog.require('goog.functions');
19 goog.require('goog.fx.Dragger');
20 goog.require('goog.fx.DragEvent');
21 goog.require('goog.testing.MockControl');
22 goog.require('goog.testing.events');
23 goog.require('goog.testing.jsunit');
24 </script>
25 <script type="text/javascript" src="events/dragger.js"></script>
26 <script type="text/javascript" src="events/event.js"></script>
27 <script type="text/javascript" src="events/eventtype.js"></script>
28 <script type="text/javascript" src="tools/tool.js"></script>
29 <script type="text/javascript" src="tools/orbittool.js"></script>
30 <script type="text/javascript" src="controllers/viewcontroller.js"> </script>
31 <script type="text/javascript">
32 goog.require('ginsu.events.Dragger');
33 goog.require('ginsu.tools.Tool');
34 goog.require('ginsu.controllers.ViewController');
35 </script>
36
37 <script type="text/javascript">
38 /**
39 * @fileoverview These unit tests are for the Ginsu ViewController
40 */
41
42 /**
43 * The global mock controller. Instanced in setUp().
44 */
45 var mockControl_;
46
47 /**
48 * Set function for each test, called by the testing framework at the
49 * start of each test. Creates the 'gs_container' div and mocks the
50 * GSPlugin API.
51 */
52 function setUp() {
53 mockControl_ = new goog.testing.MockControl();
54 createTestingDivs();
55 createGinsuMocks();
56 }
57
58 function tearDown() {
59 mockControl_.$tearDown();
60 deleteTestingDivs();
61 }
62
63 /**
64 * Test the ViewController empty constructor, this should throw an error.
65 */
66 function testEmptyConstructor() {
67 var viewController = null;
68 var caughtException = false;
69 try {
70 viewController = new ginsu.controllers.ViewController();
71 } catch(e) {
72 // This is correct behavior.
73 caughtException = true;
74 }
75 assertTrue('ViewController empty constructor', caughtException);
76 assertNull(viewController);
77 }
78
79 /**
80 * Test the ViewController constructor, passing in a valid DOM element.
81 */
82 function testConstructor() {
83 var gsViewElement = goog.dom.getElement('ginsu_view');
84 assertNotNull(gsViewElement);
85
86 var gsView = null;
87 try {
88 gsView = new ginsu.controllers.ViewController(gsViewElement);
89 } catch(e) {
90 fail('ViewController constructor');
91 }
92 assertNotNull(gsView);
93 assertNotNull(gsView.dragListener_);
94 assertTrue('ViewController must listen for start-drag events',
95 goog.events.hasListener(gsView.dragListener_,
96 goog.fx.Dragger.EventType.START, false));
97 assertTrue('ViewController must listen for drag events',
98 goog.events.hasListener(gsView.dragListener_,
99 goog.fx.Dragger.EventType.DRAG, false));
100 assertTrue('ViewController must listen for end-drag events',
101 goog.events.hasListener(gsView.dragListener_,
102 goog.fx.Dragger.EventType.END, false));
103 }
104
105 /**
106 * Test the frame function.
107 */
108 function testFrame() {
109 var gsViewElement = goog.dom.getElement('ginsu_view');
110 assertNotNull(gsViewElement);
111 var gsView = new ginsu.controllers.ViewController(gsViewElement);
112 var frame = gsView.frame();
113 assertEquals(0, frame.x);
114 assertEquals(0, frame.y);
115 assertEquals(gsViewElement.clientWidth, frame.width);
116 assertEquals(gsViewElement.clientHeight, frame.height);
117 }
118
119 /**
120 * Build the div elements used by the application.
121 */
122 function createTestingDivs() {
123 var backgroundDiv = goog.dom.createDom('div', {
124 'id': 'background',
125 'style': 'position:absolute; top:0; left:0; height:200; width:200;'
126 });
127 goog.dom.appendChild(document.body, backgroundDiv);
128 goog.dom.appendChild(backgroundDiv, goog.dom.createDom('div', {
129 'id': 'ginsu_toolbar', 'class': 'goog-toolbar'
130 }));
131 goog.dom.appendChild(backgroundDiv, goog.dom.createDom('div', {
132 'id': 'ginsu_view', 'class': 'ginsu_view'
133 }));
134 }
135
136 /**
137 * Remove all the div elements created during setup, so that later test
138 * runs don't have duplicate elements.
139 */
140 function deleteTestingDivs() {
141 var backgroundDiv = goog.dom.$('background');
142 goog.dom.removeChildren(backgroundDiv);
143 goog.dom.removeNode(backgroundDiv);
144 }
145
146 /**
147 * Attach mock functions to the |ginsu_view| element that mimic the
148 * Ginsu API. There are only three entry points, and they
149 * don't get tested here (they are tested in the client code) so it's
150 * best to just stub them out.
151 */
152 function createGinsuMocks() {
153 var gsMockDiv = goog.dom.getElement('ginsu_view');
154 gsMockDiv.valueForKey = goog.functions.constant([0, 0, 0, 1]);
155 gsMockDiv.setValueForKey = function(mockOrientation) {};
156 gsMockDiv.logMessage = function(message) {
157 top.console.log(message);
158 };
159 }
160
161 </script>
162 </head>
163 </html>
OLDNEW
« no previous file with comments | « experimental/conways_life/controllers/viewcontroller.js ('k') | experimental/conways_life/css/life.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698