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

Unified Diff: samples/tests/samples/src/swarm/SwarmTest.dart

Issue 10253022: test rename overhaul: step 13 - samples (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: samples/tests/samples/src/swarm/SwarmTest.dart
diff --git a/samples/tests/samples/src/swarm/SwarmTest.dart b/samples/tests/samples/src/swarm/SwarmTest.dart
deleted file mode 100644
index cca7ed92e788c9a8fc34b0286dc879407caff8b6..0000000000000000000000000000000000000000
--- a/samples/tests/samples/src/swarm/SwarmTest.dart
+++ /dev/null
@@ -1,156 +0,0 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-#library('swarm_tests');
-
-#import('dart:html');
-#import('../../../../swarm/swarmlib.dart');
-#import('../../../../ui_lib/base/base.dart');
-#import('../../../../ui_lib/view/view.dart');
-#import('../../../../ui_lib/util/utilslib.dart');
-#import('../../../../../lib/unittest/unittest.dart');
-#import('../../../../../lib/unittest/html_config.dart');
-
-// TODO(jmesserly): these would probably be easier to debug if they were written
-// in the WebKit layout test style, so we could easy compare that the DOM is
-// what we expect it to be after performing some simulated user actions.
-
-void main() {
- useHtmlConfiguration();
- Swarm swarm = new Swarm();
- UIStateProxy state = new UIStateProxy(swarm.sections);
- swarm.state = state;
- swarm.run();
- // TODO(jmesserly): should be adding the full stylesheet here
- Dom.addStyle('''
- .story-content {
- -webkit-column-width: 300px;
- -webkit-column-gap: 26px; /* 2em */
- }''');
-
- getStoryNode() => swarm.frontView.storyView.node;
-
- getView(Section section) {
- return CollectionUtils.find(swarm.frontView.sections.childViews,
- (view) => view.section == section);
- }
-
- getHistory(Article article) {
- final feed = article.dataSource;
- return {
- 'section': CollectionUtils.find(swarm.sections,
- (s) => s.feeds.indexOf(feed, 0) >= 0).id,
- 'feed': feed.id,
- 'article': article.id
- };
- }
-
- asyncTest('BackButton', 1, () {
- _serialInvokeAsync([() {
- Expect.equals(null, swarm.frontView.storyView); // verify initial state
-
- // Make sure we've transitioned to the section
- // In the real app, this isn't needed because ConveyorView fires the
- // transition end event before we can click a story.
- SectionView section = getView(swarm.sections[0]);
- section.showSources();
- },
- () {
- final item = swarm.sections[0].feeds[2].articles[1];
- state.loadFromHistory(getHistory(item));
-
- Expect.equals(item, state.currentArticle.value);
-
- Expect.isFalse(getStoryNode().classes.contains(CSS.HIDDEN_STORY));
-
- state.loadFromHistory({});
-
- Expect.equals(null, state.currentArticle.value);
- Expect.isTrue(getStoryNode().classes.contains(CSS.HIDDEN_STORY));
- callbackDone();
- }]);
- });
-
- test('StoryView', () {
- state.clearHistory();
-
- Expect.isTrue(getStoryNode().classes.contains(CSS.HIDDEN_STORY));
-
- final dataSourceView =
- swarm.frontView.currentSection.dataSourceView.getSubview(0);
- final itemView = dataSourceView.itemsView.getSubview(0);
- // TODO(jacobr): remove this null check. This is likely due to tests
- // running without the correct CSS to size the window so that some items
- // are visible.
- if (itemView != null) {
- click(itemView.node);
- state.expectHistory([getHistory(itemView.item)]);
- }
- });
-
- test('SliderMenu', () {
- Expect.equals(getView(swarm.sections[0]), swarm.frontView.currentSection);
-
- // Find the first slider menu item, and click on the one next after it.
- click(document.queryAll('.${CSS.SM_ITEM}')[1]);
-
- Expect.equals(getView(swarm.sections[1]), swarm.frontView.currentSection);
-
- // Find the first menu item again and click on it.
- click(document.query('.${CSS.SM_ITEM}'));
-
- Expect.equals(getView(swarm.sections[0]), swarm.frontView.currentSection);
- });
-}
-
-/** Triggers the click event, like [http://api.jquery.com/click/] */
-click(Element element) {
- // TODO(rnystrom): This should be on the DOM API somewhere.
- MouseEvent event = new MouseEvent('click', window, 1, 0, 0, 0, 0, 0);
- element.on.click.dispatch(event);
-}
-
-
-/** A proxy so we can intercept history calls */
-class UIStateProxy extends SwarmState {
- List<Map<String, String>> history;
-
- UIStateProxy(Sections dataModel) : super(dataModel) {
- clearHistory();
- }
-
- void pushToHistory() {
- history.add(toHistory());
- super.pushToHistory();
- }
-
- void clearHistory() {
- history = new List<Map<String, String>>();
- }
-
- void expectHistory(List<Map<String, String>> entries) {
- Expect.equals(entries.length, history.length);
- for (int i = 0; i < entries.length; i++) {
- Map e = entries[i];
- Map h = history[i];
- Expect.equals(e['article'], h['article']);
- }
- clearHistory();
- }
-}
-
-void _serialInvokeAsync(List closures) {
- final length = closures.length;
- if (length > 0) {
- int i = 0;
- void invokeNext() {
- closures[i]();
- i++;
- if (i < length) {
- window.setTimeout(invokeNext, 0);
- }
- }
- window.setTimeout(invokeNext, 0);
- }
-}

Powered by Google App Engine
This is Rietveld 408576698