/*
 * Copyright 2011 Opera Software ASA
 *
 * 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.
 */

package com.opera.core.systems;

import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriverException;

public class EcmaScriptTest extends TestBase {

  String xpath =
    ".//input[(not(@type) or (@type!=\"file\" and @type!=\"radio\" and @typ" +
      "e!=\"checkbox\" and @type!=\"submit\" and @type!=\"reset\" and @type!=\"" +
      "image\" and @type!=\"button\" and @type!=\"hidden\" and @type!=\"url\" " +
      "and @type!=\"datetime\" and @type!=\"date\" and @type!=\"month\" and @" +
      "type!=\"week\" and @type!=\"time\" and @type!=\"datetime-local\" and @" +
      "type!=\"range\" and @type!=\"color\")) and @class='foo'] | .//textarea" +
      "[@class='foo']";

  @Before
  public void setUp() {
    driver.navigate().to(
      "data:text/html;charset=utf-8,%3Cinput%20id%3D%22wrong%22%20class%3" +
        "D%22foo%22%20%2F%3E%3Cinput%20id%3D%22correct%22%20class%3D%22foo%" +
        "22%20%2F%3E"
    );
  }

  @Test
  public void testXPath() {
    Exception exception = null;

    try {
      driver.findElementsByXPath(xpath);
    } catch (WebDriverException e) {
      exception = e;
    }

    Assert.assertNull(exception);
  }

  // TODO: Add more tests for actually checking that it returns a list of elements.

}

@@ -630,16 +630,75 @@
 stems;%0A%0A
+import static org.junit.Assert.*;%0A%0Aimport java.util.List;%0A%0A
 import j
@@ -814,16 +814,55 @@
 ception;
+%0Aimport org.openqa.selenium.WebElement;
 %0A%0Apublic
@@ -1912,89 +1912,305 @@
 %0A%0A  
-// TODO: Add more tests for actually checking that it returns a list of elements.
+@Test%0A  public void testObjectOfElements() throws Exception %7B%0A    List%3CWebElement%3E divs = (List%3CWebElement%3E) driver.executeScript(%22return %5Bdocument.createElement('div'), document.createElement('div')%5D%22);%0A    for (WebElement el : divs) %7B%0A      Assert.assertEquals(%22DIV%22, el.getTagName());%0A    %7D%0A  %7D
 %0A%0A%7D%0A

Add test for array of elements