CSC/ECE 517 Spring 2018- Project M1803: Implement a web page fuzzer to find rendering mismatches (Part 2): Difference between revisions
Line 14: | Line 14: | ||
:2) Add a module to the program that enable generating random content specific to the <head> element (such as inline CSS content inside of a <style> element) and add it to the generated output | :2) Add a module to the program that enable generating random content specific to the <head> element (such as inline CSS content inside of a <style> element) and add it to the generated output | ||
::- As per the file [https://github.com/asoni3/Random-web-content-generator---CSC-517-OSS-Project/blob/master/code_generation.py code_generation.py], here is the code which generates random content specific to the head element and adds style on top of it. | ::- As per the file [https://github.com/asoni3/Random-web-content-generator---CSC-517-OSS-Project/blob/master/code_generation.py code_generation.py], here is the code which generates random content specific to the head element and adds style on top of it. | ||
< | <source lang="py"> | ||
#generate a skeleton HTML file with a doctype, head element, and body element and adds CSS to it | #generate a skeleton HTML file with a doctype, head element, and body element and adds CSS to it | ||
def RandomHtml(): | def RandomHtml(): | ||
Line 58: | Line 58: | ||
chars = random.randrange(2, 10) | chars = random.randrange(2, 10) | ||
return ''.join(random.choice(string.ascii_lowercase) for _ in range(chars)) | return ''.join(random.choice(string.ascii_lowercase) for _ in range(chars)) | ||
</ | </source> |
Revision as of 21:12, 8 April 2018
By Alexander Simpson(adsimps3), Abhay Soni (asoni3), Dileep badveli (dbadvel) and Jake Batty(jbatty)
By Alexander Simpson(adsimps3), Abhay Soni (asoni3), Dileep badveli (dbadvel) and Jake Batty(jbatty)
Introduction
This goal of this project is to create a tool that can randomly generate valid HTML pages, then automatically load them in both Firefox and Servo using the WebDriver protocol and report if both engines render the content identically. As a part of the OSS project we created a tool which generates random valid HTML files and automated servo. Now, as a part of this project we are supposed to finish the subsequent steps in the project which is explained below.
Previous Work (Part of the OSS Project)
As per the project description, we were expected to complete the initial steps. The implementation is explained below for each of these steps.
- 1) In a new repository, create a program that can generate a skeleton HTML file with a doctype, head element, and body element, print the result to stdout
- - Here is the link to the repository which contains code_generation.py file which will be used to generate random valid HTML files.
- 2) Add a module to the program that enable generating random content specific to the <head> element (such as inline CSS content inside of a <style> element) and add it to the generated output
- - As per the file code_generation.py, here is the code which generates random content specific to the head element and adds style on top of it.
#generate a skeleton HTML file with a doctype, head element, and body element and adds CSS to it
def RandomHtml():
yield '<!DOCTYPE html>'
yield '<html>\r\n'
yield ' RANDOMCSSCONTENTHERETOBEPLACED '
yield '<body>\r\n'
yield RandomSection()
yield '</body>\r\n</html>\r\n'
RandomCSS()
#generate a random section
def RandomSection():
global css
global count
for x in range(0,random.randrange(5,10)):
random_header_number = random.randrange(3,5)
#Since there are headers of six different sizes in HTML, we generate a random header size between range 3 to 5.
if not '<h'+str(random_header_number)+' id=a"'+str(count)+'">' in css_contents:
css_contents[count] = '<h'+str(random_header_number)+'>'
count+=1
yield '<p id="a'+str(count)+'">'
count+=1
#For a paragraph, we choose to keep it's size in between the range of 2 to 15 sentences.
num_of_sentences = random.randrange(2, 15)
for _ in range(num_of_sentences):
yield RandomSentence()
yield '</p>\r'
yield ('\n')
#generate a random sentence using random range function
def RandomSentence():
global count
num_of_words = random.randrange(5, 20)
yield (' '.join(RandomWord() for _ in range(num_of_words)) + '.')
#A random word of 2 to 10 characters length is generated which is used above to create a random sentence and which is later used to generate a paragraph
def RandomWord():
chars = random.randrange(2, 10)
return ''.join(random.choice(string.ascii_lowercase) for _ in range(chars))