2009-06-03 18:27:08 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
package com.ibm.wala.cast.js.test;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URL;
|
|
|
|
|
2011-04-04 21:20:31 +00:00
|
|
|
import org.junit.Before;
|
2009-07-27 23:21:22 +00:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2011-04-13 16:27:15 +00:00
|
|
|
import com.ibm.wala.cast.js.html.IHtmlParser;
|
|
|
|
import com.ibm.wala.cast.js.html.IHtmlParserFactory;
|
2011-04-04 21:20:31 +00:00
|
|
|
import com.ibm.wala.cast.js.html.JSSourceExtractor;
|
2011-04-13 16:27:15 +00:00
|
|
|
import com.ibm.wala.cast.js.html.WebUtil;
|
2011-04-04 21:20:31 +00:00
|
|
|
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
|
2009-06-03 18:27:08 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
2009-06-22 15:06:12 +00:00
|
|
|
import com.ibm.wala.util.CancelException;
|
2009-06-03 18:27:08 +00:00
|
|
|
|
2009-07-27 23:21:22 +00:00
|
|
|
public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape {
|
2009-06-03 18:27:08 +00:00
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
justThisTest(TestSimplePageCallGraphShape.class);
|
|
|
|
}
|
2011-04-04 21:20:31 +00:00
|
|
|
|
2011-04-13 16:27:15 +00:00
|
|
|
protected abstract IHtmlParser getParser();
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() {
|
|
|
|
WebUtil.setFactory(new IHtmlParserFactory() {
|
|
|
|
public IHtmlParser getParser() {
|
|
|
|
return getParser();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-04-04 21:20:31 +00:00
|
|
|
@Before
|
|
|
|
public void config() {
|
2012-01-06 21:21:26 +00:00
|
|
|
JSSourceExtractor.USE_TEMP_NAME = false;
|
|
|
|
JSSourceExtractor.DELETE_UPON_EXIT = true;
|
2011-04-04 21:20:31 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 18:27:08 +00:00
|
|
|
private static final Object[][] assertionsForPage1 = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "page1.html" } },
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "page1.html", new String[] { "page1.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "page1.html/__WINDOW_MAIN__",
|
2009-06-03 18:27:08 +00:00
|
|
|
new String[] { "prologue.js/substring",
|
|
|
|
"prologue.js/indexOf",
|
2010-09-09 14:09:16 +00:00
|
|
|
"preamble.js/DOMDocument/write_to_dom",
|
2009-06-03 18:27:08 +00:00
|
|
|
"prologue.js/encodeURI"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-27 23:21:22 +00:00
|
|
|
@Test public void testPage1() throws IOException, IllegalArgumentException, CancelException {
|
2009-06-03 18:27:08 +00:00
|
|
|
URL url = getClass().getClassLoader().getResource("pages/page1.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, assertionsForPage1);
|
|
|
|
}
|
|
|
|
|
2010-09-09 14:09:16 +00:00
|
|
|
private static final Object[][] assertionsForPage2 = new Object[][] {
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { ROOT, new String[] { "page2.html" } },
|
|
|
|
new Object[] { "page2.html", new String[] { "page2.html/__WINDOW_MAIN__" } }
|
2010-09-09 14:09:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testPage2() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/page2.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, assertionsForPage2);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForPage11 = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "page11.html" } },
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "page11.html", new String[] { "page11.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "page11.html/__WINDOW_MAIN__",
|
2010-09-09 14:09:16 +00:00
|
|
|
new String[] { "preamble.js/DOMDocument/createElement",
|
|
|
|
"preamble.js/DOMNode/appendChild",
|
|
|
|
"preamble.js/DOMElement/setAttribute"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testCrawlPage11() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/crawl/page11.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, assertionsForPage11);
|
|
|
|
}
|
|
|
|
|
2011-04-04 21:20:31 +00:00
|
|
|
private static final Object[][] assertionsForPage11b = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "page11b.html" } },
|
|
|
|
new Object[] { "page11b.html", new String[] { "page11b.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "page11b.html/__WINDOW_MAIN__",
|
|
|
|
new String[] { "preamble.js/DOMDocument/createElement",
|
|
|
|
"preamble.js/DOMNode/appendChild",
|
|
|
|
"preamble.js/DOMElement/setAttribute"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testCrawlPage11b() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/crawl/page11b.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, assertionsForPage11b);
|
|
|
|
}
|
|
|
|
|
2010-09-09 14:09:16 +00:00
|
|
|
private static final Object[][] assertionsForPage12 = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "page12.html" } },
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "page12.html", new String[] { "page12.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "page12.html/__WINDOW_MAIN__",
|
2011-04-13 16:27:15 +00:00
|
|
|
new String[] { "page12.html/__WINDOW_MAIN__/make_node0/make_node3/make_node4/button_onclick" } },
|
|
|
|
new Object[] { "page12.html/__WINDOW_MAIN__/make_node0/make_node3/make_node4/button_onclick",
|
2011-04-04 21:20:31 +00:00
|
|
|
new String[] { "page12.html/__WINDOW_MAIN__/callXHR"
|
2010-09-09 14:09:16 +00:00
|
|
|
}
|
|
|
|
},
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[]{ "page12.html/__WINDOW_MAIN__/callXHR",
|
2010-09-09 14:09:16 +00:00
|
|
|
new String[] { "preamble.js/DOMDocument/getElementById",
|
|
|
|
"preamble.js/_XMLHttpRequest/xhr_open",
|
|
|
|
"preamble.js/_XMLHttpRequest/xhr_send"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Object[]{ "preamble.js/_XMLHttpRequest/xhr_open",
|
|
|
|
new String[] { "preamble.js/_XMLHttpRequest/xhr_orsc_handler" }
|
|
|
|
},
|
|
|
|
new Object[]{ "preamble.js/_XMLHttpRequest/xhr_send",
|
|
|
|
new String[] { "preamble.js/_XMLHttpRequest/xhr_orsc_handler" }
|
|
|
|
},
|
|
|
|
new Object[]{ "preamble.js/_XMLHttpRequest/xhr_orsc_handler",
|
2011-04-04 21:20:31 +00:00
|
|
|
new String[] { "page12.html/__WINDOW_MAIN__/handler" }
|
2010-09-09 14:09:16 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testCrawlPage12() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/crawl/page12.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, assertionsForPage12);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForPage13 = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "page13.html" } },
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "page13.html", new String[] { "page13.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "page13.html/__WINDOW_MAIN__",
|
2011-04-13 16:27:15 +00:00
|
|
|
new String[] { "page13.html/__WINDOW_MAIN__/make_node0/make_node3/make_node4/button_onclick" } },
|
|
|
|
new Object[] { "page13.html/__WINDOW_MAIN__/make_node0/make_node3/make_node4/button_onclick",
|
2011-04-04 21:20:31 +00:00
|
|
|
new String[] { "page13.html/__WINDOW_MAIN__/callXHR"
|
2010-09-09 14:09:16 +00:00
|
|
|
}
|
|
|
|
},
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[]{ "page13.html/__WINDOW_MAIN__/callXHR",
|
2010-09-09 14:09:16 +00:00
|
|
|
new String[] { "preamble.js/DOMDocument/getElementById",
|
|
|
|
"preamble.js/_XMLHttpRequest/xhr_open",
|
|
|
|
"preamble.js/_XMLHttpRequest/xhr_setRequestHeader",
|
|
|
|
"preamble.js/_XMLHttpRequest/xhr_send"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Object[]{ "preamble.js/_XMLHttpRequest/xhr_open",
|
|
|
|
new String[] { "preamble.js/_XMLHttpRequest/xhr_orsc_handler" }
|
|
|
|
},
|
|
|
|
new Object[]{ "preamble.js/_XMLHttpRequest/xhr_send",
|
|
|
|
new String[] { "preamble.js/_XMLHttpRequest/xhr_orsc_handler" }
|
|
|
|
},
|
|
|
|
new Object[]{ "preamble.js/_XMLHttpRequest/xhr_orsc_handler",
|
2011-04-04 21:20:31 +00:00
|
|
|
new String[] { "page13.html/__WINDOW_MAIN__/handler" }
|
2010-09-09 14:09:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testCrawlPage13() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/crawl/page13.html");
|
2011-04-04 21:20:31 +00:00
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
2010-09-09 14:09:16 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForPage13);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForPage15 = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "page15.html" } },
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "page15.html", new String[] { "page15.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "page15.html/__WINDOW_MAIN__",
|
2011-04-13 16:27:15 +00:00
|
|
|
new String[] { "page15.html/__WINDOW_MAIN__/make_node0/make_node3/body_onload"
|
2010-09-09 14:09:16 +00:00
|
|
|
}
|
|
|
|
},
|
2011-04-13 16:27:15 +00:00
|
|
|
new Object[] { "page15.html/__WINDOW_MAIN__/make_node0/make_node3/body_onload",
|
2011-04-04 21:20:31 +00:00
|
|
|
new String[] { "page15.html/__WINDOW_MAIN__/changeUrls" }
|
2010-09-09 14:09:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testCrawlPage15() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/crawl/page15.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, assertionsForPage15);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForPage16 = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "page16.html" } },
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "page16.html", new String[] { "page16.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "page16.html/__WINDOW_MAIN__",
|
2011-04-13 16:27:15 +00:00
|
|
|
new String[] { "page16.html/__WINDOW_MAIN__/make_node0/make_node3/make_node4/a_onclick"
|
2010-09-09 14:09:16 +00:00
|
|
|
}
|
|
|
|
},
|
2011-04-13 16:27:15 +00:00
|
|
|
new Object[] { "page16.html/__WINDOW_MAIN__/make_node0/make_node3/make_node4/a_onclick",
|
2011-04-04 21:20:31 +00:00
|
|
|
new String[] { "page16.html/__WINDOW_MAIN__/changeUrls" }
|
2010-09-09 14:09:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testCrawlPage16() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/crawl/page16.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, assertionsForPage16);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForPage17 = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "page17.html" } },
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "page17.html", new String[] { "page17.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "page17.html/__WINDOW_MAIN__",
|
|
|
|
new String[] { "page17.html/__WINDOW_MAIN__/loadScript" }
|
2010-09-09 14:09:16 +00:00
|
|
|
},
|
|
|
|
new Object[] { "preamble.js",
|
2011-04-04 21:20:31 +00:00
|
|
|
new String[] { "page17.html/__WINDOW_MAIN__/loadScript/_page17_handler" }
|
2010-09-09 14:09:16 +00:00
|
|
|
},
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "page17.html/__WINDOW_MAIN__/loadScript/_page17_handler",
|
|
|
|
new String[] { "page17.html/__WINDOW_MAIN__/callFunction" }
|
2010-09-09 14:09:16 +00:00
|
|
|
},
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "page17.html/__WINDOW_MAIN__/callFunction",
|
2010-09-09 14:09:16 +00:00
|
|
|
new String[] { "suffix:changeUrls" }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testCrawlPage17() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/crawl/page17.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, assertionsForPage17);
|
|
|
|
}
|
2010-11-05 00:36:44 +00:00
|
|
|
|
|
|
|
private static final Object[][] assertionsForApolloExample = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "apollo-example.html" } },
|
2011-04-04 21:20:31 +00:00
|
|
|
new Object[] { "apollo-example.html", new String[] { "apollo-example.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "apollo-example.html/__WINDOW_MAIN__", new String[] { "apollo-example.html/__WINDOW_MAIN__/signon" } },
|
|
|
|
new Object[] { "apollo-example.html/__WINDOW_MAIN__/signon", new String[] { "preamble.js/DOMWindow/window_open" } }
|
2010-11-05 00:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testApolloExample() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/apollo-example.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, assertionsForApolloExample);
|
|
|
|
}
|
|
|
|
|
2010-11-22 17:46:30 +00:00
|
|
|
@Test public void testNojs() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/nojs.html");
|
|
|
|
// all we need is for it to finish building CG successfully.
|
2011-04-04 21:20:31 +00:00
|
|
|
Util.makeHTMLCG(url);
|
2010-11-22 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 15:31:53 +00:00
|
|
|
@Test public void testPage4() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/page4.html");
|
2011-04-04 21:20:31 +00:00
|
|
|
Util.makeHTMLCG(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] sourceAssertionsForList = new Object[][] {
|
|
|
|
new Object[]{ "suffix:update_display", "list.html", 9, 18 },
|
|
|
|
new Object[]{ "suffix:update_with_item", "list.html", 14, 16 },
|
|
|
|
new Object[]{ "suffix:add_item", "list.html", 20, 25 },
|
|
|
|
new Object[]{ "suffix:collection", "pages/collection.js", 2, 14 },
|
|
|
|
new Object[]{ "suffix:collection_add", "pages/collection.js", 7, 13 },
|
|
|
|
new Object[]{ "suffix:forall_elt", "pages/collection.js", 9, 12 },
|
|
|
|
new Object[]{ "suffix:forall_base", "pages/collection.js", 4, 4 }
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testList() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/list.html");
|
|
|
|
JSCFABuilder builder = Util.makeHTMLCGBuilder(url);
|
|
|
|
CallGraph CG = builder.makeCallGraph(builder.getOptions());
|
2011-04-28 19:08:06 +00:00
|
|
|
Util.dumpCG(builder.getPointerAnalysis(), CG);
|
2011-04-04 21:20:31 +00:00
|
|
|
verifySourceAssertions(CG, sourceAssertionsForList);
|
|
|
|
}
|
|
|
|
|
2011-04-13 16:27:15 +00:00
|
|
|
@Test public void testIframeTest2() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/iframeTest2.html");
|
|
|
|
Util.makeHTMLCG(url);
|
|
|
|
}
|
|
|
|
|
2011-05-23 16:27:07 +00:00
|
|
|
private static final Object[][] assertionsForWindowx = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "windowx.html" } },
|
|
|
|
new Object[] { "windowx.html", new String[] { "windowx.html/__WINDOW_MAIN__" } },
|
|
|
|
new Object[] { "windowx.html/__WINDOW_MAIN__", new String[] { "windowx.html/__WINDOW_MAIN__/_f2", "windowx.html/__WINDOW_MAIN__/_f4" } },
|
|
|
|
new Object[] { "windowx.html/__WINDOW_MAIN__/_f2", new String[] { "windowx.html/__WINDOW_MAIN__/_f1" } },
|
|
|
|
new Object[] { "windowx.html/__WINDOW_MAIN__/_f4", new String[] { "windowx.html/__WINDOW_MAIN__/_f3" } }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test public void testWindowx() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/windowx.html");
|
|
|
|
JSCFABuilder builder = Util.makeHTMLCGBuilder(url);
|
|
|
|
CallGraph CG = builder.makeCallGraph(builder.getOptions());
|
|
|
|
Util.dumpCG(builder.getPointerAnalysis(), CG);
|
|
|
|
verifyGraphAssertions(CG, assertionsForWindowx);
|
|
|
|
}
|
|
|
|
|
2011-04-04 21:20:31 +00:00
|
|
|
/*
|
|
|
|
@Test public void testJQuery() throws IOException, IllegalArgumentException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/jquery.html");
|
2010-11-23 15:31:53 +00:00
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
}
|
2011-05-23 16:27:07 +00:00
|
|
|
*/
|
2010-11-23 15:31:53 +00:00
|
|
|
|
2011-05-23 16:27:07 +00:00
|
|
|
/*
|
2011-04-04 21:20:31 +00:00
|
|
|
@Test public void testDojoTest() throws IllegalArgumentException, IOException, CancelException {
|
|
|
|
URL url = getClass().getClassLoader().getResource("pages/dojo/test.html");
|
|
|
|
CallGraph CG = Util.makeHTMLCG(url);
|
|
|
|
verifyGraphAssertions(CG, null);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2009-06-03 18:27:08 +00:00
|
|
|
}
|