def testUnmatchedEndIfBlock(self):
        '''Tests that an unmatched </if> raises an exception.'''

        files = {
            'index.html':
            '''
      <!DOCTYPE HTML>
      <html>
        <if expr="lang == 'fr'">
          bonjour
        </if>
        <if expr='lang == "de"'>
          hallo
        </if>
        </if>
      </html>
      ''',
        }

        tmp_dir = util.TempDir(files)

        with self.assertRaises(Exception) as cm:
            html_inline.GetResourceFilenames(tmp_dir.GetPath('index.html'),
                                             None)
        self.failUnlessEqual(cm.exception.message, 'Unmatched </if>')
        tmp_dir.CleanUp()
示例#2
0
  def testGetResourceFilenames(self):
    '''Tests that all included files are returned by GetResourceFilenames.'''

    files = {
      'index.html': '''
      <!DOCTYPE HTML>
      <html>
        <head>
          <link rel="stylesheet" href="test.css">
          <link rel="stylesheet"
              href="really-long-long-long-long-long-test.css">
        </head>
        <body>
          <include src='test.html'>
          <include
              src="really-long-long-long-long-long-test-file-omg-so-long.html">
          <iron-icon src="[[icon]]"></iron-icon><!-- Should be ignored. -->
          <iron-icon src="{{src}}"></iron-icon><!-- Also ignored. -->
        </body>
      </html>
      ''',

      'test.html': '''
      <include src="test2.html">
      ''',

      'really-long-long-long-long-long-test-file-omg-so-long.html': '''
      <!-- This really long named resource should be included. -->
      ''',

      'test2.html': '''
      <!-- This second level resource should also be included. -->
      ''',

      'test.css': '''
      .image {
        background: url('test.png');
      }
      ''',

      'really-long-long-long-long-long-test.css': '''
      a:hover {
        font-weight: bold;  /* Awesome effect is awesome! */
      }
      ''',

      'test.png': 'PNG DATA',
    }

    source_resources = set()
    tmp_dir = util.TempDir(files)
    for filename in files:
      source_resources.add(tmp_dir.GetPath(filename))

    resources = html_inline.GetResourceFilenames(tmp_dir.GetPath('index.html'),
                                                 None)
    resources.add(tmp_dir.GetPath('index.html'))
    self.failUnlessEqual(resources, source_resources)
    tmp_dir.CleanUp()
示例#3
0
 def GetHtmlResourceFilenames(self):
     """Returns a set of all filenames inlined by this file."""
     if self.flatten_html_:
         return html_inline.GetResourceFilenames(
             self.grd_node.ToRealPath(self.GetInputPath()),
             allow_external_script=self.allow_external_script_,
             rewrite_function=lambda fp, t, d: ProcessImageSets(
                 fp, t, self.scale_factors_, d))
     return []
  def testCompressedJavaScript(self):
    '''Tests that ".src=" doesn't treat as a tag.'''

    files = {
      'index.js': '''
      if(i<j)a.src="hoge.png";
      ''',
    }

    source_resources = set()
    tmp_dir = util.TempDir(files)
    for filename in files:
      source_resources.add(tmp_dir.GetPath(filename))

    resources = html_inline.GetResourceFilenames(tmp_dir.GetPath('index.js'))
    resources.add(tmp_dir.GetPath('index.js'))
    self.failUnlessEqual(resources, source_resources)
    tmp_dir.CleanUp()
  def testCssIncludedFileNames(self):
    '''Tests that all included files from css are returned'''

    files = {
      'index.html': '''
      <!DOCTYPE HTML>
      <html>
        <head>
          <link rel="stylesheet" href="test.css">
        </head>
        <body>
        </body>
      </html>
      ''',

      'test.css': '''
      <include src="test2.css">
      ''',

      'test2.css': '''
      <include src="test3.css">
      .image {
        background: url('test.png');
      }
      ''',

      'test3.css': '''h1 {}''',

      'test.png': 'PNG DATA'
    }

    source_resources = set()
    tmp_dir = util.TempDir(files)
    for filename in files:
      source_resources.add(tmp_dir.GetPath(filename))

    resources = html_inline.GetResourceFilenames(tmp_dir.GetPath('index.html'),
                                                 None)
    resources.add(tmp_dir.GetPath('index.html'))
    self.failUnlessEqual(resources, source_resources)
    tmp_dir.CleanUp()
示例#6
0
    def testGetResourceFilenames(self):
        '''Tests that all included files are returned by GetResourceFilenames.'''

        files = {
            'index.html': '''
      <!DOCTYPE HTML>
      <html>
        <head>
          <link rel="stylesheet" href="test.css">
        </head>
        <body>
          <include src="test.html">
        </body>
      </html>
      ''',
            'test.html': '''
      <include src="test2.html">
      ''',
            'test2.html': '''
      <!-- This second level resource should also be included. -->
      ''',
            'test.css': '''
      .image {
        background: url('test.png');
      }
      ''',
            'test.png': 'PNG DATA',
        }

        source_resources = set()
        tmp_dir = util.TempDir(files)
        for filename in files:
            source_resources.add(tmp_dir.GetPath(filename))

        resources = html_inline.GetResourceFilenames(
            tmp_dir.GetPath('index.html'))
        resources.add(tmp_dir.GetPath('index.html'))
        self.failUnlessEqual(resources, source_resources)
        tmp_dir.CleanUp()