Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.distiller; | 5 package org.chromium.distiller; |
| 6 | 6 |
| 7 import com.google.gwt.core.client.JsArray; | 7 import com.google.gwt.core.client.JsArray; |
| 8 import com.google.gwt.dom.client.Document; | 8 import com.google.gwt.dom.client.Document; |
| 9 import com.google.gwt.dom.client.Element; | 9 import com.google.gwt.dom.client.Element; |
| 10 import com.google.gwt.dom.client.Node; | 10 import com.google.gwt.dom.client.Node; |
| 11 import com.google.gwt.dom.client.NodeList; | 11 import com.google.gwt.dom.client.NodeList; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Base test case for all DomDistiller js tests. Ensures that each test starts | 14 * Base test case for all DomDistiller js tests. Ensures that each test starts |
| 15 * with a fresh document. | 15 * with a fresh document. |
| 16 */ | 16 */ |
| 17 public class DomDistillerJsTestCase extends JsTestCase { | 17 public class DomDistillerJsTestCase extends JsTestCase { |
| 18 protected Element mRoot; | 18 protected Element mRoot; |
| 19 protected Element mHead; | 19 protected Element mHead; |
| 20 protected Element mBody; | 20 protected Element mBody; |
| 21 | 21 |
| 22 @Override | 22 @Override |
| 23 public void setUp() throws Exception { | 23 public void setUp() throws Exception { |
| 24 gwtSetUp(); | 24 gwtSetUp(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 protected void gwtSetUp() throws Exception { | 27 protected void gwtSetUp() throws Exception { |
| 28 mRoot = Document.get().getDocumentElement(); | 28 mRoot = Document.get().getDocumentElement(); |
| 29 JsArray<Node> attrs = DomUtil.getAttributes(mRoot); | 29 JsArray<Node> attrs = DomUtil.getAttributes(mRoot); |
| 30 String[] attrNames = new String[attrs.length()]; | |
| 30 for (int i = 0; i < attrs.length(); i++) { | 31 for (int i = 0; i < attrs.length(); i++) { |
| 31 mRoot.removeAttribute(attrs.get(i).getNodeName()); | 32 attrNames[i] = attrs.get(i).getNodeName(); |
|
mdjones
2016/03/11 16:58:09
I'm assuming the problem here was they we were mod
wychen
2016/03/11 21:56:32
Exactly. attrs is not deeply copied, so it didn't
| |
| 32 } | 33 } |
| 34 for (int i = 0; i < attrNames.length; i++) { | |
| 35 mRoot.removeAttribute(attrNames[i]); | |
| 36 } | |
| 37 assertEquals(0, DomUtil.getAttributes(mRoot).length()); | |
| 33 NodeList<Node> children = mRoot.getChildNodes(); | 38 NodeList<Node> children = mRoot.getChildNodes(); |
| 34 for (int i = children.getLength() - 1; i >= 0; i--) { | 39 for (int i = children.getLength() - 1; i >= 0; i--) { |
| 35 children.getItem(i).removeFromParent(); | 40 children.getItem(i).removeFromParent(); |
| 36 } | 41 } |
| 42 assertEquals(0, mRoot.getChildNodes().getLength()); | |
| 37 mHead = Document.get().createElement("head"); | 43 mHead = Document.get().createElement("head"); |
| 38 mRoot.appendChild(mHead); | 44 mRoot.appendChild(mHead); |
| 39 mBody = Document.get().createElement("body"); | 45 mBody = Document.get().createElement("body"); |
| 40 mRoot.appendChild(mBody); | 46 mRoot.appendChild(mBody); |
| 41 // With this, the width of chrome window won't affect the layout. | 47 // With this, the width of chrome window won't affect the layout. |
| 42 mRoot.getStyle().setProperty("width", "800px"); | 48 mRoot.getStyle().setProperty("width", "800px"); |
| 43 } | 49 } |
| 44 } | 50 } |
| OLD | NEW |