Skip to content

Commit

Permalink
Merge branch 'OPDRV-17'
Browse files Browse the repository at this point in the history
Conflicts:
	test/com/opera/core/systems/IdleTest.java
  • Loading branch information
Stuk committed Mar 2, 2011
2 parents 88c9980 + cec1135 commit 5424328
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 37 deletions.
147 changes: 110 additions & 37 deletions test/com/opera/core/systems/IdleTest.java
Expand Up @@ -2,71 +2,97 @@

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

import com.opera.core.systems.scope.internal.OperaIntervals;

public class IdleTest extends TestBase {
// Timeout vars for every test
private static long start, end;
private static long timout = OperaIntervals.OPERA_IDLE_TIMEOUT.getValue();

// Make sure we're actually using Idle, and not hitting the timeout
private static long timeout = OperaIntervals.OPERA_IDLE_TIMEOUT.getValue();

// Make sure these tests only run if OperaIdle is available
@Rule
public MethodRule random = new MethodRule() {
public Statement apply(Statement base, FrameworkMethod method, Object target) {
// If Idle available return the test
if (driver.isOperaIdleAvailable()) return base;
// otherwise return an empty statement -> test doesn't run
else return new Statement() {
@Override
public void evaluate() throws Throwable {}
};
}
};

@Before
public void setUp() {
start = end = 0;
}

@After
public void tearDown() {
// Make sure the test hasn't passed because we hit the page load
// timeout instead of using OperaIdle
Assert.assertTrue("Timout", end - start < timout);
Assert.assertTrue("Took longer than page timeout", end - start < timeout);
}

// Make sure we're actually using Idle, and not hitting the timeout
// this should be OperaIntervals.PAGE_LOAD_TIMEOUT, but JUnit requires
// a constant. This timeout is the same for all tests.
private void start() { start = System.currentTimeMillis(); }
private void stop() { end = System.currentTimeMillis(); }

@Test
public void testGet() throws Exception {
start = System.currentTimeMillis();
start();
getFixture("test.html");
end = System.currentTimeMillis();
stop();

Assert.assertEquals(fixture("test.html"), driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("test.html"));
}

@Test
public void testBack() throws Exception {
getFixture("javascript.html");

start = System.currentTimeMillis();
start();
driver.navigate().back();
end = System.currentTimeMillis();
stop();

Assert.assertEquals(fixture("test.html"), driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("test.html"));
}

@Test
public void testForward() throws Exception {
start = System.currentTimeMillis();
start();
driver.navigate().forward();
end = System.currentTimeMillis();
stop();

Assert.assertEquals(fixture("javascript.html"), driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("javascript.html"));
}

@Test
public void testBack2() throws Exception {
start = System.currentTimeMillis();
start();
driver.navigate().back();
end = System.currentTimeMillis();
stop();

Assert.assertEquals(fixture("test.html"), driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("test.html"));
}

@Test
public void testRefresh() throws Exception {
getFixture("test.html");
((OperaWebElement) driver.findElementById("input_email")).sendKeys("before refresh");

start = System.currentTimeMillis();
start();
driver.navigate().refresh();
end = System.currentTimeMillis();
stop();

Assert.assertEquals("", driver.findElementById("input_email").getValue());
}
Expand All @@ -75,22 +101,22 @@ public void testRefresh() throws Exception {
public void testClick() throws Exception {
getFixture("test.html");

start = System.currentTimeMillis();
start();
driver.findElementById("local").click();
end = System.currentTimeMillis();
stop();

Assert.assertEquals(fixture("two_input_fields.html"), driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("two_input_fields.html"));
}

@Test
public void testClickXY() throws Exception {
getFixture("test.html");

start = System.currentTimeMillis();
start();
((OperaWebElement) driver.findElementById("local")).click(3, 5);
end = System.currentTimeMillis();
stop();

Assert.assertEquals(fixture("two_input_fields.html"), driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("two_input_fields.html"));
}

@Test
Expand All @@ -101,51 +127,98 @@ public void testKeyEnter() throws Exception {
driver.findElementById("one").click();

// submit form
start = System.currentTimeMillis();
start();
driver.key("Enter");
end = System.currentTimeMillis();
stop();

// +"?" for submitted query string
Assert.assertEquals(fixture("test.html")+"?", driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("test.html?"));
}

@Test
public void testSendKeysNewline() throws Exception {
getFixture("javascript.html");

// Focus textbox
start = System.currentTimeMillis();
start();
((OperaWebElement) driver.findElementById("one")).sendKeys("\n");
end = System.currentTimeMillis();
stop();

// +"?" for submitted query string
Assert.assertEquals(fixture("test.html")+"?", driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("test.html?"));
}

@Test
public void testSetSelected() throws Exception {
getFixture("javascript.html");

// Check checkbox, fires a submit even on the form
start = System.currentTimeMillis();
start();
((OperaWebElement) driver.findElementById("check")).setSelected();
end = System.currentTimeMillis();
stop();

// +"?" for submitted query string
Assert.assertEquals(fixture("test.html")+"?", driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("test.html?"));
}

@Test
public void testSubmit() throws Exception {
getFixture("javascript.html");

// Check checkbox, fires a submit even on the form
start = System.currentTimeMillis();
start();
((OperaWebElement) driver.findElementById("test_form")).submit();
end = System.currentTimeMillis();
stop();

// +"?" for submitted query string
Assert.assertEquals(fixture("test.html")+"?", driver.getCurrentUrl());
Assert.assertTrue(driver.getCurrentUrl().endsWith("test.html?"));
}

/* Begin testing OperaIdle conditions */

@Test
public void testEcmascriptLoop() throws Exception {
start();
getFixture("idle/ecmascript-loop.html");
stop();

Assert.assertEquals("done", driver.findElementById("out").getText());
}

@Test
public void testEcmascriptTimeout() throws Exception {
start();
getFixture("idle/ecmascript-timeout.html");
stop();

Assert.assertEquals("done", driver.findElementById("out").getText());
}

@Test
public void testEcmascriptTimeoutLoop() throws Exception {
start();
getFixture("idle/ecmascript-timeout-loop.html");
stop();

Assert.assertEquals("done", driver.findElementById("out").getText());
}

@Test
public void testReflow() throws Exception {
// Need #box to activate the :target pseudo class
start();
getFixture("idle/reflow.html#box");
stop();

OperaWebElement box = (OperaWebElement) driver.findElementById("box");
Assert.assertEquals(200, box.getSize().width);
}

@Test
public void testMetarefresh() throws Exception {
getFixture("idle/metarefresh.html");

Assert.assertTrue(driver.getCurrentUrl().endsWith("test.html?"));
}

@Test
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/idle/ecmascript-event.html
@@ -0,0 +1,17 @@
<!doctype HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Timeout ecmascript fixture</title>
</head>
<body>
<h1 id="out">Waiting</h1>
<p id="result"></p>

<script type="text/javascript">
setTimeout(function() {
document.getElementById("out").innerHTML = "done";
}, 1000);
</script>
</body>
</html>
27 changes: 27 additions & 0 deletions test/fixtures/idle/ecmascript-loop.html
@@ -0,0 +1,27 @@
<!doctype HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Looping ecmascript fixture</title>
</head>
<body>
<h1 id="out">looping</h1>
<p id="result"></p>

<script type="text/javascript">
// Sieve of Eratosthenes
function sieve(N){
var n, p, primes=[], str=[];
for(n=2; n<N/2; n++){
if(primes[n]) { continue; }
for(p=2*n; p<=N; p+=n){ primes[p]=true; }
}
for(n=2; n<=N; n++){ if(!primes[n]) str.push(n); }
return str.join(', ');
}

document.getElementById("result").innerHTML = sieve(1000000);
document.getElementById("out").innerHTML = "done";
</script>
</body>
</html>
25 changes: 25 additions & 0 deletions test/fixtures/idle/ecmascript-timeout-loop.html
@@ -0,0 +1,25 @@
<!doctype HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Timeout ecmascript fixture</title>
</head>
<body>
<h1 id="out">Waiting</h1>
<p id="result"></p>

<script type="text/javascript">
var loops = 0;
function loop() {
loops++
if (loops > 2) {
document.getElementById("out").innerHTML = "done";
} else {
setTimeout(loop, 500);
}
}

loop();
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions test/fixtures/idle/ecmascript-timeout.html
@@ -0,0 +1,17 @@
<!doctype HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Timeout ecmascript fixture</title>
</head>
<body>
<h1 id="out">Waiting</h1>
<p id="result"></p>

<script type="text/javascript">
setTimeout(function() {
document.getElementById("out").innerHTML = "done";
}, 1000);
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions test/fixtures/idle/metarefresh.html
@@ -0,0 +1,11 @@
<!doctype HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Meta tag refresh fixture</title>
<meta http-equiv="refresh" content="1;url=../test.html" >
</head>
<body>
<h1>Hello</h1>
</body>
</html>
27 changes: 27 additions & 0 deletions test/fixtures/idle/reflow.html
@@ -0,0 +1,27 @@
<!doctype HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSS animation fixture. Should cause reflows.</title>
<style type="text/css">
#box {
float: left;
background-color: #FCC;
width: 100px;
height: 100px;
-o-transition-property: width background-color;
-o-transition-duration: 2s;
-o-transition-timing-function: linear;
}

#box:target {
background-color: #CCF;
width: 200px;
}
</style>
</head>
<body>
<div id="box">box</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis augue lacus, porttitor eget tristique vel, imperdiet nec sapien. Aenean et lectus in odio auctor auctor sed id nibh. Maecenas tempus orci nec lorem elementum nec tincidunt urna laoreet. Phasellus felis quam, condimentum eu semper ac, laoreet at tellus. Donec nisl augue, consectetur tristique mattis non, dapibus in orci. Sed a purus orci. Pellentesque gravida, quam vitae rutrum dapibus, elit elit venenatis felis, feugiat suscipit velit turpis eu nulla. Nam sit amet orci eget sapien imperdiet molestie et sed velit. Etiam pretium venenatis erat, pulvinar tempor augue congue a. Morbi ultrices vulputate lorem molestie ullamcorper. Integer bibendum augue nisi, id cursus elit. Praesent quis pellentesque ante. Pellentesque feugiat, ipsum quis faucibus feugiat, justo est egestas sapien, ac tempor ipsum nibh vitae justo. Curabitur non metus eget risus convallis suscipit eget quis quam. Aenean pellentesque aliquam imperdiet. Sed scelerisque, quam sit amet molestie laoreet, mi lectus adipiscing purus, vulputate auctor augue urna nec mi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris fringilla, elit pellentesque eleifend dictum, dui enim vehicula massa, rutrum gravida lorem nunc pulvinar risus. Donec luctus lectus id nibh suscipit iaculis.</p>
</body>
</html>

0 comments on commit 5424328

Please sign in to comment.