Add basic testing framework for gr-editor

Bug: Issue 8366
Change-Id: I0851e543d8128e57a3bb3815fc5039194efd5a2e
diff --git a/README.md b/README.md
index ad44581..272ad35 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,9 @@
 # CodeMirror Editor
 
-A plugin that uses CodeMirror to provide a rich code editing experience in PolyGerrit.
\ No newline at end of file
+A plugin that uses CodeMirror to provide a rich code editing experience in PolyGerrit.
+
+## Testing
+
+This plugin uses [polymer-cli](https://www.polymer-project.org/1.0/docs/tools/polymer-cli#install) to test.
+
+After `bower install`, running `polymer test -l chrome` will run all tests in Chrome, and running `polymer serve` and navigating to http://127.0.0.1:8081/components/codemirror-editor/gr-editor/gr-editor_test.html allows for manual debugging.
\ No newline at end of file
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..1ef5317
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,17 @@
+{
+  "name": "codemirror-editor",
+  "authors": [
+    "kaspern@google.com"
+  ],
+  "license": "http://www.apache.org/licenses/LICENSE-2.0",
+  "dependencies": {
+    "polymer": "Polymer/polymer#^1.0.0",
+    "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
+    "codemirror-minified": "^5.37.0"
+  },
+  "devDependencies": {
+    "web-component-tester": "Polymer/web-component-tester#^6.0.0",
+    "iron-test-helpers": "^2.0.0"
+  },
+  "private": true
+}
diff --git a/gr-editor/gr-editor.html b/gr-editor/gr-editor.html
index fd8673e..f9c8869 100644
--- a/gr-editor/gr-editor.html
+++ b/gr-editor/gr-editor.html
@@ -14,6 +14,8 @@
 limitations under the License.
 -->
 
+<link rel="import" href="../bower_components/polymer/polymer.html">
+
 <link rel="import" href="gr-editor-styles.html">
 
 <script src="../bower_components/codemirror-minified/lib/codemirror.js"></script>
diff --git a/gr-editor/gr-editor_test.html b/gr-editor/gr-editor_test.html
new file mode 100644
index 0000000..aa9a36e
--- /dev/null
+++ b/gr-editor/gr-editor_test.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<!--
+@license
+Copyright (C) 2018 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
+<title>gr-editor</title>
+
+<link rel="import" href="../bower_components/iron-test-helpers/iron-test-helpers.html">
+<link rel="import" href="gr-editor.html">
+<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
+<script src="../../../bower_components/web-component-tester/browser.js"></script>
+
+<script>void(0);</script>
+
+<test-fixture id="basic">
+  <template>
+    <gr-editor></gr-editor>
+  </template>
+</test-fixture>
+
+<script>
+suite('gr-editor tests', () => {
+  let element;
+  let sandbox;
+
+  setup(() => {
+    sandbox = sinon.sandbox.create();
+
+    stub('gr-editor', {
+      // Stub ready because it exists before attached in the Polymer lifecycle,
+      // and the editor plugin initializes in the attached callback.
+      ready() {
+        this.fileType = 'text/x-php';
+        this.fileContent = '<?php echo test; ?>';
+        this.prefs = {};
+      },
+    })
+
+    element = fixture('basic');
+  });
+
+  teardown(() => {
+    sandbox.restore();
+  });
+
+  test('renders', () => {
+    flushAsynchronousOperations();
+
+    assert.ok(element.mirror);
+    assert.equal(element.mirror.getValue(), element.fileContent);
+  });
+});
+</script>
\ No newline at end of file
diff --git a/test/index.html b/test/index.html
new file mode 100644
index 0000000..822cd45
--- /dev/null
+++ b/test/index.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<!--
+@license
+Copyright (C) 2018 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
+<title>Test Runner</title>
+<meta charset="utf-8">
+<script src="../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
+<script src="../bower_components/web-component-tester/browser.js"></script>
+<script>
+  WCT.loadSuites([
+    '../gr-editor/gr-editor_test.html',
+    '../gr-editor/gr-editor_test.html?dom=shadow',
+  ]);
+</script>
\ No newline at end of file