Skip to content

Commit

Permalink
Some work in the repo to prepare the way for exmaples and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed May 8, 2014
1 parent 3f054c6 commit d60be29
Show file tree
Hide file tree
Showing 70 changed files with 17,112 additions and 167 deletions.
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory" : "bower_components"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
bower_components
compiled
dist
sauce_connect.log
Expand Down
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: node_js

node_js:
- 0.10

env:
global:
- BROWSER_PROVIDER_READY_FILE=/tmp/sauce-connect-ready
- LOGS_DIR=/tmp/angular-router-build/logs
- SAUCE_USERNAME=angular-ci
- SAUCE_ACCESS_KEY=9b988f434ff8-fbca-8aa4-4ae3-35442987

install:
- mkdir -p $LOGS_DIR
- ./scripts/sauce_connect_setup.sh
- npm install
- npm install -g gulp
- npm install -g karma-cli
- ./scripts/wait_for_browser_provider.sh

script:
- gulp build
- gulp templates
- karma start --single-run --browsers SL_Chrome --reporters dots
- ./scripts/run_protractor_tests.sh

after_script:
39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
[![Build Status](https://travis-ci.org/angular/templating.png?branch=master)](https://travis-ci.org/angular/templating)
# Angular 2.0 Router

# Router Prototype
This is a prototype of a new router for Angular 2.0. Its feature set is based on the router used by Durandal. This router has been ported to ES6. It has also had bugs fixed from Durandal's router and a few new features have been added to faciliate greater flexibility. The internals of the router have been re-designed to use a customizable async pipeline. The screen activator has also had a similar re-design. Generally speaking, it allows for tons of customization at almost every point, understands basic conventions, has sensible defaults, etc.

This is a prototype of a new router for Angular 2.0. Its feature set is based on the router used by Durandal (which was the second client-side router I've written...this is the third...well, maybe the 4th actually. I may have lost count). This router has been ported to ES6. It has also had bugs fixed from Durandal's router and a few new features have been added to faciliate greater flexibility. The internals of the router have been re-designed to use a customizable async pipeline. The screen activator has also had a similar re-design. Generally speaking, it allows for tons of customization at almost every point, understands basic conventions, has sensible defaults, etc. The intersting stuff is in the src folder. Don't pay attention to the rest for now.
> **Note:** This prototype should fullfill almost, if not all, the requirements mentioned in the Angular 2.0 router design doc.
> *Note:* This prototype should fullfill almost, if not all, the requirements mentioned in the Angular 2.0 router design doc.
## Setup

1. Install [NodeJS](http://nodejs.org/)
2. At the command prompt install [Gulp](http://gulpjs.com/) with `npm install -g gulp`
3. At the command promit install [Bower](http://bower.io/) with `npm install -g bower`
4. From the repo, install npm dependencies with `npm install`
5. From the repo, install bower dependencies with `bower install`

## Running the Samples

1. At the command prompt, start the development web server with `gulp build watch serve`
2. Open a browser and navigate to [http://localhost:8000/temp/examples/index.html](http://localhost:8000/temp/examples/index.html)

> **Note:** The examples don't currently contain an example of the router. This is based on a branch of our templating engine. The router source still needs updating to match the new templating code.
## Development

1. At the command prompt, install the cli for [Karma](http://karma-runner.github.io/) with `npm install -g karma-cli`
2. At the command prompt, start karma with `karma start`
3. Add new tests to the `test` folder. Be sure to give them an extension of `.spec.js`.

### Code Style Guide

* Use 2 spaces as tab, see .editorconfig

## Features

Expand All @@ -31,10 +54,4 @@ This is a prototype of a new router for Angular 2.0. Its feature set is based on
* Has a custom TemplateDirective `router-port` which serves as a composition site for the router's active view.

## To Do
* Probably should write some tests...

## Develop
npm install
karma start

Use 2 spaces as tab, see .editorconfig
* Probably should write some tests...
23 changes: 23 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "router",
"version": "0.0.0",
"homepage": "https://github.com/eisenbergeffect/router",
"authors": [
"Rob Eisenberg <[email protected]>"
],
"moduleType": [
"es6"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"app/bower_components",
"test",
"tests"
],
"dependencies": {
"polymer": "Polymer/polymer#~0.2.3"
}
}
24 changes: 24 additions & 0 deletions chromedriver/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Instructions:
1) Apply selenium_shadow_dom.patch to selenium.

$ cd <selenium_dir>
$ git apply <path_to_templating/chromedriver>/selenium_shadow_dom.patch
$ ./go //javascript/chrome-driver:atoms

2) Copy the output to chromedriver.

$ cp build/javascript/chrome-driver/atoms.* \
<chromium_dir>/src/third_party/webdriver/

3) Apply the chromedriver_shadow_dom.patch to chromedriver.

$ cd <chromium_dir>
$ git apply <README_dir>/chromedriver_shadow_dom.patch

4) Build chromedriver.

$ ninja -C out/Release chromedriver

5) Copy the new version of chromedriver to this directory

$ cp <chromium dir>/src/out/Release/chromedriver <path_to_templating/chromedriver>/
Binary file added chromedriver/chromedriver_linux.zip
Binary file not shown.
Binary file added chromedriver/chromedriver_mac.zip
Binary file not shown.
157 changes: 157 additions & 0 deletions chromedriver/chromedriver_shadow_dom.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
From 29859b18c82760e13304ab8d74fee5ac1a0eda73 Mon Sep 17 00:00:00 2001
From: Vojta Jina <[email protected]>
Date: Tue, 22 Apr 2014 17:01:38 -0700
Subject: [PATCH] Allow shadom DOM, using both prefixed and unprefixed

---
chrome/test/chromedriver/js/call_function.js | 77 +++++++++++++++++++++-------
chrome/test/chromedriver/js/focus.js | 15 +++++-
2 files changed, 72 insertions(+), 20 deletions(-)

diff --git a/chrome/test/chromedriver/js/call_function.js b/chrome/test/chromedriver/js/call_function.js
index f31f95f..aa2ef93 100644
--- a/chrome/test/chromedriver/js/call_function.js
+++ b/chrome/test/chromedriver/js/call_function.js
@@ -32,7 +32,18 @@ var ELEMENT_KEY = 'ELEMENT';
* @const
* @type {boolean}
*/
-var SHADOW_DOM_ENABLED = typeof ShadowRoot === 'function';
+var SHADOW_DOM_ENABLED = false;
+var ShadowRootCls = null;
+var SHADOW_ROOT_PROPERTY = null;
+if (typeof ShadowRoot === 'function') {
+ ShadowRootCls = ShadowRoot;
+ SHADOW_ROOT_PROPERTY = 'shadowRoot';
+ SHADOW_DOM_ENABLED = true;
+} else if (typeof WebKitShadowRoot === 'function') {
+ ShadowRootCls = WebKitShadowRoot;
+ SHADOW_ROOT_PROPERTY = 'webkitShadowRoot';
+ SHADOW_DOM_ENABLED = true;
+}

/**
* A cache which maps IDs <-> cached objects for the purpose of identifying
@@ -97,12 +108,44 @@ Cache.prototype = {
* @return {boolean} If the nodes is reachable.
*/
isNodeReachable_: function(node) {
- var nodeRoot = getNodeRoot(node);
- if (nodeRoot == document)
- return true;
- else if (SHADOW_DOM_ENABLED && nodeRoot instanceof ShadowRoot)
+ while (node) {
+ if (node == document)
+ return true;
+
+ // WC3 spec states "The parentNode and parentElement attributes of the
+ // shadow root object must always return null." Use alternate approach to
+ // determine if it is reachable.
+ if (SHADOW_DOM_ENABLED && node instanceof ShadowRootCls)
+ return this.isShadowRootReachable_(node);
+
+ node = node.parentNode;
+ }
+ return false;
+ },
+
+ /**
+ * @private
+ * @param {!WebKitShadowRoot} shadow_root
+ * @param {Node} [node=document]
+ */
+ isShadowRootReachable_: function(shadow_root, node) {
+ if (node == null)
+ node = document;
+
+ if (node == shadow_root) {
return true;
+ }

+ if (node[SHADOW_ROOT_PROPERTY]
+ && this.isShadowRootReachable_(shadow_root, node[SHADOW_ROOT_PROPERTY])) {
+ return true;
+ }
+ var children = node.childNodes;
+ for (var i = 0; i < children.length; i++) {
+ var child = children[i];
+ if (this.isShadowRootReachable_(shadow_root, child))
+ return true;
+ }
return false;
}
};
@@ -144,11 +187,9 @@ function getPageCache(opt_doc) {
function wrap(value) {
if (typeof(value) == 'object' && value != null) {
var nodeType = value['nodeType'];
- if (nodeType == NodeType.ELEMENT || nodeType == NodeType.DOCUMENT
- || (SHADOW_DOM_ENABLED && value instanceof ShadowRoot)) {
+ if (nodeType == NodeType.ELEMENT || nodeType == NodeType.DOCUMENT) {
var wrapped = {};
- var root = getNodeRoot(value);
- wrapped[ELEMENT_KEY] = getPageCache(root).storeItem(value);
+ wrapped[ELEMENT_KEY] = getPageCache(value.ownerDocument).storeItem(value);
return wrapped;
}

@@ -204,15 +245,15 @@ function unwrap(value, cache) {
function callFunction(shadowHostIds, func, args, opt_unwrappedReturn) {
var cache = getPageCache();
cache.clearStale();
- if (shadowHostIds && SHADOW_DOM_ENABLED) {
- for (var i = 0; i < shadowHostIds.length; i++) {
- var host = cache.retrieveItem(shadowHostIds[i]);
- // TODO(zachconrad): Use the olderShadowRoot API when available to check
- // all of the shadow roots.
- cache = getPageCache(host.webkitShadowRoot);
- cache.clearStale();
- }
- }
+// if (shadowHostIds && SHADOW_DOM_ENABLED) {
+// for (var i = 0; i < shadowHostIds.length; i++) {
+// var host = cache.retrieveItem(shadowHostIds[i]);
+// // TODO(zachconrad): Use the olderShadowRoot API when available to check
+// // all of the shadow roots.
+// cache = getPageCache(host.webkitShadowRoot);
+// cache.clearStale();
+// }
+// }

if (opt_unwrappedReturn)
return func.apply(null, unwrap(args, cache));
diff --git a/chrome/test/chromedriver/js/focus.js b/chrome/test/chromedriver/js/focus.js
index 2945a34..0243d80 100644
--- a/chrome/test/chromedriver/js/focus.js
+++ b/chrome/test/chromedriver/js/focus.js
@@ -24,7 +24,7 @@ function focus(element) {
// input, which still have setSelectionRange defined. For chrome 29+, V8
// throws a DOMException with code InvalidStateError.
var doc = element.ownerDocument || element;
- var prevActiveElement = doc.activeElement;
+ var prevActiveElement = getActiveElement(doc);
if (element != prevActiveElement && prevActiveElement)
prevActiveElement.blur();
element.focus();
@@ -38,6 +38,17 @@ function focus(element) {
throw error;
}
}
- if (element != doc.activeElement)
+ if (element != getActiveElement(doc))
throw new Error('cannot focus element');
}
+
+function getActiveElement(doc) {
+ var activeElement = doc.activeElement;
+ var shadowRootProperty = activeElement.hasOwnProperty('shadowRoot') ? 'shadowRoot' : 'webkitShadowRoot';
+
+ while (activeElement[shadowRootProperty]
+ && activeElement[shadowRootProperty].activeElement) {
+ activeElement = activeElement[shadowRootProperty].activeElement;
+ }
+ return activeElement;
+}
--
1.9.0

Loading

0 comments on commit d60be29

Please sign in to comment.