Ejemplo n.º 1
0
def test_generate_preview_with_additional_backgrounds(write_svg_to_png_mock,
                                                      resize_image_mock,
                                                      pngcrush_image_mock):
    write_svg_to_png_mock.return_value = True

    theme_manifest = {
        "images": {
            "headerURL": "empty.png",
            "additional_backgrounds": ["weta_for_tiling.png"],
        },
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
        },
        "properties": {
            "additional_backgrounds_alignment": ["top"],
            "additional_backgrounds_tiling": ["repeat-x"],
        },
    }
    addon = addon_factory()
    generate_static_theme_preview(theme_manifest, HEADER_ROOT,
                                  addon.current_version.pk)

    assert resize_image_mock.call_count == 3
    assert write_svg_to_png_mock.call_count == 3
    assert pngcrush_image_mock.call_count == 3

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(header_preview, amo.THEME_PREVIEW_SIZES['header'],
                  write_svg_to_png_mock.call_args_list[0][0],
                  resize_image_mock.call_args_list[0][0],
                  pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(list_preview, amo.THEME_PREVIEW_SIZES['list'],
                  write_svg_to_png_mock.call_args_list[1][0],
                  resize_image_mock.call_args_list[1][0],
                  pngcrush_image_mock.call_args_list[1][0])

    # And finally the new single Preview
    single_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['single']['position'])
    check_preview(single_preview, amo.THEME_PREVIEW_SIZES['single'],
                  write_svg_to_png_mock.call_args_list[2][0],
                  resize_image_mock.call_args_list[2][0],
                  pngcrush_image_mock.call_args_list[2][0])

    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    single_svg = write_svg_to_png_mock.call_args_list[2][0][0]
    check_render_additional(header_svg, 680)
    check_render_additional(list_svg, 760)
    check_render_additional(single_svg, 720)
Ejemplo n.º 2
0
def test_generate_static_theme_preview_with_chrome_properties(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock):
    write_svg_to_png_mock.return_value = True
    theme_manifest = {
        "images": {
            "theme_frame": "transparent.gif"
        },
        "colors": {
            "frame": [123, 45, 67],  # 'accentcolor'
            "tab_background_text": [9, 87, 65],  # 'textcolor'
            "bookmark_text": [0, 0, 0],  # 'toolbar_text'
        }
    }
    addon = addon_factory()
    generate_static_theme_preview(
        theme_manifest, HEADER_ROOT, addon.current_version.pk)

    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert pngcrush_image_mock.call_count == 2

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(
        header_preview, amo.THEME_PREVIEW_SIZES['header'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0][0],
        pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(
        list_preview, amo.THEME_PREVIEW_SIZES['list'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1][0],
        pngcrush_image_mock.call_args_list[1][0])

    colors = []
    # check each of our colors above was converted to css codes
    chrome_colors = {
        'bookmark_text': 'toolbar_text',
        'frame': 'accentcolor',
        'tab_background_text': 'textcolor',
    }
    for (chrome_prop, firefox_prop) in chrome_colors.items():
        color_list = theme_manifest['colors'][chrome_prop]
        color = 'rgb(%s, %s, %s)' % tuple(color_list)
        colors.append('class="%s" fill="%s"' % (firefox_prop, color))

    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    check_render(header_svg, 'transparent.gif', 1,
                 'xMaxYMin meet', 'image/gif', True, colors, 680, 92, 680)
    check_render(list_svg, 'transparent.gif', 1,
                 'xMaxYMin meet', 'image/gif', True, colors, 760, 92, 760)
Ejemplo n.º 3
0
def test_generate_static_theme_preview_with_chrome_properties(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock):
    write_svg_to_png_mock.return_value = True
    theme_manifest = {
        "images": {
            "theme_frame": "transparent.gif"
        },
        "colors": {
            "frame": [123, 45, 67],  # 'accentcolor'
            "tab_background_text": [9, 87, 65],  # 'textcolor'
            "bookmark_text": [0, 0, 0],  # 'toolbar_text'
        }
    }
    addon = addon_factory()
    generate_static_theme_preview(
        theme_manifest, HEADER_ROOT, addon.current_version.pk)

    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert pngcrush_image_mock.call_count == 2

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(
        header_preview, amo.THEME_PREVIEW_SIZES['header'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0][0],
        pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(
        list_preview, amo.THEME_PREVIEW_SIZES['list'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1][0],
        pngcrush_image_mock.call_args_list[1][0])

    colors = []
    # check each of our colors above was converted to css codes
    chrome_colors = {
        'bookmark_text': 'toolbar_text',
        'frame': 'accentcolor',
        'tab_background_text': 'textcolor',
    }
    for (chrome_prop, firefox_prop) in chrome_colors.items():
        color_list = theme_manifest['colors'][chrome_prop]
        color = 'rgb(%s, %s, %s)' % tuple(color_list)
        colors.append('class="%s" fill="%s"' % (firefox_prop, color))

    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    check_render(header_svg, 'transparent.gif', 1,
                 'xMaxYMin meet', 'image/gif', True, colors, 680, 92, 680)
    check_render(list_svg, 'transparent.gif', 1,
                 'xMaxYMin meet', 'image/gif', True, colors, 760, 92, 760)
Ejemplo n.º 4
0
def test_generate_static_theme_preview(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock,
        header_url, header_height, preserve_aspect_ratio, mimetype, valid_img):
    write_svg_to_png_mock.return_value = True
    theme_manifest = {
        "images": {
        },
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
            "toolbar_text": "#b5ba5b",
            "toolbar_field": "#cc29cc",
            "toolbar_field_text": "#17747d"
        }
    }
    if header_url is not None:
        theme_manifest['images']['headerURL'] = header_url
    addon = addon_factory()
    generate_static_theme_preview(
        theme_manifest, HEADER_ROOT, addon.current_version.pk)

    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert pngcrush_image_mock.call_count == 2

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(
        header_preview, amo.THEME_PREVIEW_SIZES['header'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0][0],
        pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(
        list_preview, amo.THEME_PREVIEW_SIZES['list'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1][0],
        pngcrush_image_mock.call_args_list[1][0])

    # Now check the svg renders
    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    colors = ['class="%s" fill="%s"' % (key, color)
              for (key, color) in theme_manifest['colors'].items()]
    check_render(header_svg, header_url, header_height,
                 preserve_aspect_ratio, mimetype, valid_img, colors,
                 680, 92, 680)
    check_render(list_svg, header_url, header_height,
                 preserve_aspect_ratio, mimetype, valid_img, colors,
                 760, 92, 760)
Ejemplo n.º 5
0
def test_generate_static_theme_preview(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock,
        header_url, header_height, preserve_aspect_ratio, mimetype, valid_img):
    write_svg_to_png_mock.return_value = True
    theme_manifest = {
        "images": {
        },
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
            "toolbar_text": "#b5ba5b",
            "toolbar_field": "#cc29cc",
            "toolbar_field_text": "#17747d"
        }
    }
    if header_url is not None:
        theme_manifest['images']['headerURL'] = header_url
    addon = addon_factory()
    generate_static_theme_preview(
        theme_manifest, HEADER_ROOT, addon.current_version.pk)

    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert pngcrush_image_mock.call_count == 2

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(
        header_preview, amo.THEME_PREVIEW_SIZES['header'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0][0],
        pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(
        list_preview, amo.THEME_PREVIEW_SIZES['list'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1][0],
        pngcrush_image_mock.call_args_list[1][0])

    # Now check the svg renders
    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    colors = ['class="%s" fill="%s"' % (key, color)
              for (key, color) in theme_manifest['colors'].items()]
    check_render(header_svg, header_url, header_height,
                 preserve_aspect_ratio, mimetype, valid_img, colors,
                 680, 92, 680)
    check_render(list_svg, header_url, header_height,
                 preserve_aspect_ratio, mimetype, valid_img, colors,
                 760, 92, 760)
Ejemplo n.º 6
0
def test_generate_static_theme_preview(
        write_svg_to_png_mock, pngcrush_image_mock, resize_image_mock,
        header_url, header_height, preserve_aspect_ratio, mimetype):
    write_svg_to_png_mock.return_value = (789, 101112)
    resize_image_mock.return_value = (123, 456), (789, 101112)
    theme_manifest = {
        "images": {
            "headerURL": header_url
        },
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
            "toolbar_text": "#b5ba5b",
            "toolbar_field": "#cc29cc",
            "toolbar_field_text": "#17747d"
        }
    }
    header_root = os.path.join(
        settings.ROOT, 'src/olympia/versions/tests/static_themes/')
    addon = addon_factory()
    preview = VersionPreview.objects.create(version=addon.current_version)
    generate_static_theme_preview(theme_manifest, header_root, preview)

    write_svg_to_png_mock.call_count == 1
    assert pngcrush_image_mock.call_count == 1
    assert pngcrush_image_mock.call_args_list[0][0][0] == preview.image_path
    ((svg_content, png_path), _) = write_svg_to_png_mock.call_args
    assert png_path == preview.image_path
    assert resize_image_mock.call_count == 1
    assert resize_image_mock.call_args_list[0][0] == (
        png_path,
        preview.thumbnail_path,
        amo.ADDON_PREVIEW_SIZES[0],
    )

    preview.reload()
    assert preview.sizes == {'image': [789, 101112], 'thumbnail': [123, 456]}

    # check header is there.
    assert 'width="680" height="100" xmlns="http://www.w3.org/2000/' in (
        svg_content)
    # check image xml is correct
    image_tag = (
        '<image id="svg-header-img" width="680" height="%s" '
        'preserveAspectRatio="%s"' % (header_height, preserve_aspect_ratio))
    assert image_tag in svg_content, svg_content
    # and image content is included and was encoded
    with storage.open(header_root + header_url, 'rb') as header_file:
        header_blob = header_file.read()
    base_64_uri = 'data:%s;base64,%s' % (mimetype, b64encode(header_blob))
    assert 'xlink:href="%s"></image>' % base_64_uri in svg_content
    # check each of our colors above was included
    for (key, color) in theme_manifest['colors'].items():
        snippet = 'class="%s" fill="%s"' % (key, color)
        assert snippet in svg_content
Ejemplo n.º 7
0
def test_generate_static_theme_preview_with_chrome_properties(
        write_svg_to_png_mock, pngcrush_image_mock, resize_image_mock):
    write_svg_to_png_mock.return_value = (789, 101112)
    resize_image_mock.return_value = (123, 456), (789, 101112)
    theme_manifest = {
        "images": {
            "theme_frame": "transparent.gif"
        },
        "colors": {
            "frame": [123, 45, 67],  # 'accentcolor'
            "tab_background_text": [9, 87, 65],  # 'textcolor'
            "bookmark_text": [0, 0, 0],  # 'toolbar_text'
        }
    }
    header_root = os.path.join(settings.ROOT,
                               'src/olympia/versions/tests/static_themes/')
    addon = addon_factory()
    preview = VersionPreview.objects.create(version=addon.current_version)
    generate_static_theme_preview(theme_manifest, header_root, preview)

    write_svg_to_png_mock.call_count == 1
    assert pngcrush_image_mock.call_count == 1
    assert pngcrush_image_mock.call_args_list[0][0][0] == preview.image_path
    ((svg_content, png_path), _) = write_svg_to_png_mock.call_args
    assert png_path == preview.image_path
    assert resize_image_mock.call_count == 1
    assert resize_image_mock.call_args_list[0][0] == (
        png_path,
        preview.thumbnail_path,
        amo.ADDON_PREVIEW_SIZES[0],
    )

    # check image xml is correct
    image_tag = ('<image id="svg-header-img" width="680" height="%s" '
                 'preserveAspectRatio="%s"' % (1, 'xMaxYMin meet'))
    assert image_tag in svg_content, svg_content
    # and image content is included and was encoded
    with storage.open(header_root + 'transparent.gif', 'rb') as header_file:
        header_blob = header_file.read()
    base_64_uri = 'data:%s;base64,%s' % ('image/gif', b64encode(header_blob))
    assert 'xlink:href="%s"></image>' % base_64_uri in svg_content
    # check each of our colors above was converted to css codes
    chrome_colors = {
        'bookmark_text': 'toolbar_text',
        'frame': 'accentcolor',
        'tab_background_text': 'textcolor',
    }
    for (chrome_prop, firefox_prop) in chrome_colors.items():
        color_list = theme_manifest['colors'][chrome_prop]
        color = 'rgb(%s, %s, %s)' % tuple(color_list)
        snippet = 'class="%s" fill="%s"' % (firefox_prop, color)
        assert snippet in svg_content
Ejemplo n.º 8
0
def test_generate_static_theme_preview_with_chrome_properties(
        write_svg_to_png_mock, pngcrush_image_mock):
    write_svg_to_png_mock.return_value = True
    theme_manifest = {
        "images": {
            "theme_frame": "transparent.gif"
        },
        "colors": {
            "frame": [123, 45, 67],  # 'accentcolor'
            "tab_background_text": [9, 87, 65],  # 'textcolor'
            "bookmark_text": [0, 0, 0],  # 'toolbar_text'
        }
    }
    addon = addon_factory()
    preview = VersionPreview.objects.create(version=addon.current_version)
    generate_static_theme_preview(theme_manifest, HEADER_ROOT, preview.pk)

    write_svg_to_png_mock.call_count == 2
    (image_svg_content, png_path) = write_svg_to_png_mock.call_args_list[0][0]
    assert png_path == preview.image_path
    (thumb_svg_content, png_path) = write_svg_to_png_mock.call_args_list[1][0]
    assert png_path == preview.thumbnail_path

    assert pngcrush_image_mock.call_count == 2
    assert pngcrush_image_mock.call_args_list[0][0][0] == preview.image_path
    assert pngcrush_image_mock.call_args_list[1][0][0] == (
        preview.thumbnail_path)

    preview.reload()
    assert preview.sizes == {
        'image': list(amo.THEME_PREVIEW_SIZES['full']),
        'thumbnail': list(amo.THEME_PREVIEW_SIZES['thumb'])
    }

    colors = []
    # check each of our colors above was converted to css codes
    chrome_colors = {
        'bookmark_text': 'toolbar_text',
        'frame': 'accentcolor',
        'tab_background_text': 'textcolor',
    }
    for (chrome_prop, firefox_prop) in chrome_colors.items():
        color_list = theme_manifest['colors'][chrome_prop]
        color = 'rgb(%s, %s, %s)' % tuple(color_list)
        colors.append('class="%s" fill="%s"' % (firefox_prop, color))

    check_render(image_svg_content, 'transparent.gif', 1, 'xMaxYMin meet',
                 'image/gif', True, colors, 680, 92, 680)
    check_render(thumb_svg_content, 'transparent.gif', 1, 'xMaxYMin meet',
                 'image/gif', True, colors, 670, 64, 963)
Ejemplo n.º 9
0
def test_generate_preview_with_additional_backgrounds(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock):
    write_svg_to_png_mock.return_value = True

    theme_manifest = {
        "images": {
            "headerURL": "empty.png",
            "additional_backgrounds": ["weta_for_tiling.png"],
        },
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
        },
        "properties": {
            "additional_backgrounds_alignment": ["top"],
            "additional_backgrounds_tiling": ["repeat-x"],
        },
    }
    addon = addon_factory()
    generate_static_theme_preview(
        theme_manifest, HEADER_ROOT, addon.current_version.pk)

    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert pngcrush_image_mock.call_count == 2

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(
        header_preview, amo.THEME_PREVIEW_SIZES['header'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0][0],
        pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(
        list_preview, amo.THEME_PREVIEW_SIZES['list'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1][0],
        pngcrush_image_mock.call_args_list[1][0])

    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    check_render_additional(header_svg, 680)
    check_render_additional(list_svg, 760)
Ejemplo n.º 10
0
def test_generate_static_theme_preview(write_svg_to_png_mock,
                                       pngcrush_image_mock, header_url,
                                       header_height, preserve_aspect_ratio,
                                       mimetype, valid_img):
    write_svg_to_png_mock.return_value = True
    theme_manifest = {
        "images": {},
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
            "toolbar_text": "#b5ba5b",
            "toolbar_field": "#cc29cc",
            "toolbar_field_text": "#17747d"
        }
    }
    if header_url is not None:
        theme_manifest['images']['headerURL'] = header_url
    addon = addon_factory()
    preview = VersionPreview.objects.create(version=addon.current_version)
    generate_static_theme_preview(theme_manifest, HEADER_ROOT, preview.pk)

    write_svg_to_png_mock.call_count == 2
    (image_svg_content, png_path) = write_svg_to_png_mock.call_args_list[0][0]
    assert png_path == preview.image_path
    (thumb_svg_content, png_path) = write_svg_to_png_mock.call_args_list[1][0]
    assert png_path == preview.thumbnail_path

    assert pngcrush_image_mock.call_count == 2
    assert pngcrush_image_mock.call_args_list[0][0][0] == preview.image_path
    assert pngcrush_image_mock.call_args_list[1][0][0] == (
        preview.thumbnail_path)

    preview.reload()
    assert preview.sizes == {
        'image': list(amo.THEME_PREVIEW_SIZES['full']),
        'thumbnail': list(amo.THEME_PREVIEW_SIZES['thumb'])
    }

    colors = [
        'class="%s" fill="%s"' % (key, color)
        for (key, color) in theme_manifest['colors'].items()
    ]

    check_render(image_svg_content, header_url, header_height,
                 preserve_aspect_ratio, mimetype, valid_img, colors, 680, 92,
                 680)
    check_render(thumb_svg_content, header_url, header_height,
                 preserve_aspect_ratio, mimetype, valid_img, colors, 670, 64,
                 963)
Ejemplo n.º 11
0
def test_generate_static_theme_preview_with_chrome_properties(
        write_svg_to_png_mock, pngcrush_image_mock):
    write_svg_to_png_mock.return_value = True
    theme_manifest = {
        "images": {
            "theme_frame": "transparent.gif"
        },
        "colors": {
            "frame": [123, 45, 67],  # 'accentcolor'
            "tab_background_text": [9, 87, 65],  # 'textcolor'
            "bookmark_text": [0, 0, 0],  # 'toolbar_text'
        }
    }
    addon = addon_factory()
    preview = VersionPreview.objects.create(version=addon.current_version)
    generate_static_theme_preview(theme_manifest, HEADER_ROOT, preview.pk)

    write_svg_to_png_mock.call_count == 2
    (image_svg_content, png_path) = write_svg_to_png_mock.call_args_list[0][0]
    assert png_path == preview.image_path
    (thumb_svg_content, png_path) = write_svg_to_png_mock.call_args_list[1][0]
    assert png_path == preview.thumbnail_path

    assert pngcrush_image_mock.call_count == 2
    assert pngcrush_image_mock.call_args_list[0][0][0] == preview.image_path
    assert pngcrush_image_mock.call_args_list[1][0][0] == (
        preview.thumbnail_path)

    preview.reload()
    assert preview.sizes == {
        'image': list(amo.THEME_PREVIEW_SIZES['full']),
        'thumbnail': list(amo.THEME_PREVIEW_SIZES['thumb'])}

    colors = []
    # check each of our colors above was converted to css codes
    chrome_colors = {
        'bookmark_text': 'toolbar_text',
        'frame': 'accentcolor',
        'tab_background_text': 'textcolor',
    }
    for (chrome_prop, firefox_prop) in chrome_colors.items():
        color_list = theme_manifest['colors'][chrome_prop]
        color = 'rgb(%s, %s, %s)' % tuple(color_list)
        colors.append('class="%s" fill="%s"' % (firefox_prop, color))

    check_render(image_svg_content, 'transparent.gif', 1,
                 'xMaxYMin meet', 'image/gif', True, colors, 680, 92, 680)
    check_render(thumb_svg_content, 'transparent.gif', 1,
                 'xMaxYMin meet', 'image/gif', True, colors, 670, 64, 963)
Ejemplo n.º 12
0
def test_generate_static_theme_preview(
        write_svg_to_png_mock, pngcrush_image_mock,
        header_url, header_height, preserve_aspect_ratio, mimetype, valid_img):
    write_svg_to_png_mock.return_value = True
    theme_manifest = {
        "images": {
        },
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
            "toolbar_text": "#b5ba5b",
            "toolbar_field": "#cc29cc",
            "toolbar_field_text": "#17747d"
        }
    }
    if header_url is not None:
        theme_manifest['images']['headerURL'] = header_url
    addon = addon_factory()
    preview = VersionPreview.objects.create(version=addon.current_version)
    generate_static_theme_preview(theme_manifest, HEADER_ROOT, preview.pk)

    write_svg_to_png_mock.call_count == 2
    (image_svg_content, png_path) = write_svg_to_png_mock.call_args_list[0][0]
    assert png_path == preview.image_path
    (thumb_svg_content, png_path) = write_svg_to_png_mock.call_args_list[1][0]
    assert png_path == preview.thumbnail_path

    assert pngcrush_image_mock.call_count == 2
    assert pngcrush_image_mock.call_args_list[0][0][0] == preview.image_path
    assert pngcrush_image_mock.call_args_list[1][0][0] == (
        preview.thumbnail_path)

    preview.reload()
    assert preview.sizes == {
        'image': list(amo.THEME_PREVIEW_SIZES['full']),
        'thumbnail': list(amo.THEME_PREVIEW_SIZES['thumb'])}

    colors = ['class="%s" fill="%s"' % (key, color)
              for (key, color) in theme_manifest['colors'].items()]

    check_render(image_svg_content, header_url, header_height,
                 preserve_aspect_ratio, mimetype, valid_img, colors,
                 680, 92, 680)
    check_render(thumb_svg_content, header_url, header_height,
                 preserve_aspect_ratio, mimetype, valid_img, colors,
                 670, 64, 963)
Ejemplo n.º 13
0
def test_generate_preview_with_additional_backgrounds(write_svg_to_png_mock,
                                                      pngcrush_image_mock):
    write_svg_to_png_mock.return_value = True

    theme_manifest = {
        "images": {
            "headerURL": "empty.png",
            "additional_backgrounds": ["weta_for_tiling.png"],
        },
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
        },
        "properties": {
            "additional_backgrounds_alignment": ["top"],
            "additional_backgrounds_tiling": ["repeat-x"],
        },
    }
    addon = addon_factory()
    preview = VersionPreview.objects.create(version=addon.current_version)
    generate_static_theme_preview(theme_manifest, HEADER_ROOT, preview.pk)

    write_svg_to_png_mock.call_count == 2
    (image_svg_content, png_path) = write_svg_to_png_mock.call_args_list[0][0]
    assert png_path == preview.image_path
    (thumb_svg_content, png_path) = write_svg_to_png_mock.call_args_list[1][0]
    assert png_path == preview.thumbnail_path

    assert pngcrush_image_mock.call_count == 2
    assert pngcrush_image_mock.call_args_list[0][0][0] == preview.image_path
    assert pngcrush_image_mock.call_args_list[1][0][0] == (
        preview.thumbnail_path)

    preview.reload()
    assert preview.sizes == {
        'image': list(amo.THEME_PREVIEW_SIZES['full']),
        'thumbnail': list(amo.THEME_PREVIEW_SIZES['thumb'])
    }

    check_render_additional(image_svg_content, 680)
    check_render_additional(thumb_svg_content, 963)
Ejemplo n.º 14
0
def test_generate_preview_with_additional_backgrounds(
        write_svg_to_png_mock, pngcrush_image_mock):
    write_svg_to_png_mock.return_value = True

    theme_manifest = {
        "images": {
            "headerURL": "empty.png",
            "additional_backgrounds": ["weta_for_tiling.png"],
        },
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
        },
        "properties": {
            "additional_backgrounds_alignment": ["top"],
            "additional_backgrounds_tiling": ["repeat-x"],
        },
    }
    addon = addon_factory()
    preview = VersionPreview.objects.create(version=addon.current_version)
    generate_static_theme_preview(theme_manifest, HEADER_ROOT, preview.pk)

    write_svg_to_png_mock.call_count == 2
    (image_svg_content, png_path) = write_svg_to_png_mock.call_args_list[0][0]
    assert png_path == preview.image_path
    (thumb_svg_content, png_path) = write_svg_to_png_mock.call_args_list[1][0]
    assert png_path == preview.thumbnail_path

    assert pngcrush_image_mock.call_count == 2
    assert pngcrush_image_mock.call_args_list[0][0][0] == preview.image_path
    assert pngcrush_image_mock.call_args_list[1][0][0] == (
        preview.thumbnail_path)

    preview.reload()
    assert preview.sizes == {
        'image': list(amo.THEME_PREVIEW_SIZES['full']),
        'thumbnail': list(amo.THEME_PREVIEW_SIZES['thumb'])}

    check_render_additional(image_svg_content, 680)
    check_render_additional(thumb_svg_content, 963)
Ejemplo n.º 15
0
def test_generate_preview_with_additional_backgrounds(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock,
        extract_colors_from_image_mock, index_addons_mock):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [
        {'h': 9, 's': 8, 'l': 7, 'ratio': 0.6}
    ]

    theme_manifest = {
        "images": {
            "theme_frame": "empty.png",
            "additional_backgrounds": ["weta_for_tiling.png"],
        },
        "colors": {
            "textcolor": "#123456",
            # Just textcolor, to test the template defaults and fallbacks.
        },
        "properties": {
            "additional_backgrounds_alignment": ["top"],
            "additional_backgrounds_tiling": ["repeat-x"],
        },
    }
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(
        settings.ROOT,
        'src/olympia/devhub/tests/addons/static_theme_tiled.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 3
    assert write_svg_to_png_mock.call_count == 3
    assert pngcrush_image_mock.call_count == 3

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(
        header_preview, amo.THEME_PREVIEW_SIZES['header'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0][0],
        pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(
        list_preview, amo.THEME_PREVIEW_SIZES['list'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1][0],
        pngcrush_image_mock.call_args_list[1][0])

    # And finally the new single Preview
    single_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['single']['position'])
    check_preview(
        single_preview, amo.THEME_PREVIEW_SIZES['single'],
        write_svg_to_png_mock.call_args_list[2][0],
        resize_image_mock.call_args_list[2][0],
        pngcrush_image_mock.call_args_list[2][0])

    # These defaults are mostly defined in the xml template
    default_colors = {
        "frame": "rgba(229,230,232,1)",  # amo.THEME_FRAME_COLOR_DEFAULT
        "tab_background_text": "#123456",  # the only one defined in 'manifest'
        "bookmark_text": "#123456",  # should default to tab_background_text
        "toolbar_field": "rgba(255,255,255,1)",
        "toolbar_field_text": "",
        "tab_line": "rgba(0,0,0,0.25)",
        "tab_selected": "rgba(0,0,0,0)",
    }
    colors = ['class="%s" fill="%s"' % (key, color)
              for (key, color) in default_colors.items()]

    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    single_svg = write_svg_to_png_mock.call_args_list[2][0][0]
    check_render_additional(force_text(header_svg), 680, colors)
    check_render_additional(force_text(list_svg), 760, colors)
    check_render_additional(force_text(single_svg), 720, colors)

    index_addons_mock.assert_called_with([addon.id])
Ejemplo n.º 16
0
def test_generate_preview_with_additional_backgrounds(
    write_svg_to_png_mock,
    pngcrush_image_mock,
    resize_image_mock,
):
    write_svg_to_png_mock.return_value = (789, 101112)
    resize_image_mock.return_value = (123, 456), (789, 101112)

    theme_manifest = {
        "images": {
            "headerURL": "empty.png",
            "additional_backgrounds": ["weta_for_tiling.png"],
        },
        "colors": {
            "accentcolor": "#918e43",
            "textcolor": "#3deb60",
        },
        "properties": {
            "additional_backgrounds_alignment": ["top"],
            "additional_backgrounds_tiling": ["repeat-x"],
        },
    }
    header_root = os.path.join(settings.ROOT,
                               'src/olympia/versions/tests/static_themes/')
    addon = addon_factory()
    preview = VersionPreview.objects.create(version=addon.current_version)
    generate_static_theme_preview(theme_manifest, header_root, preview)

    write_svg_to_png_mock.call_count == 1
    assert pngcrush_image_mock.call_count == 1
    assert pngcrush_image_mock.call_args_list[0][0][0] == preview.image_path
    ((svg_content, png_path), _) = write_svg_to_png_mock.call_args
    assert png_path == preview.image_path
    assert resize_image_mock.call_count == 1
    assert resize_image_mock.call_args_list[0][0] == (
        png_path,
        preview.thumbnail_path,
        amo.ADDON_PREVIEW_SIZES[0],
    )

    preview.reload()
    assert preview.sizes == {'image': [789, 101112], 'thumbnail': [123, 456]}

    # check additional background pattern is correct
    image_width = 270
    image_height = 200
    pattern_x_offset = (680 - image_width) / 2
    pattern_tag = (
        '<pattern id="AdditionalBackground1"\n'
        '                   width="%s" height="%s"\n'
        '                   x="%s" y="%s" patternUnits="userSpaceOnUse">' %
        (image_width, '100%', pattern_x_offset, 0))
    assert pattern_tag in svg_content, svg_content
    image_tag = '<image width="%s" height="%s"' % (image_width, image_height)
    assert image_tag in svg_content, svg_content
    rect_tag = (
        '<rect width="100%" height="100%" fill="url(#AdditionalBackground1)">'
        '</rect>')
    assert rect_tag in svg_content, svg_content
    # and image content is included and was encoded
    additional = os.path.join(header_root, 'weta_for_tiling.png')
    with storage.open(additional, 'rb') as header_file:
        header_blob = header_file.read()
    base_64_uri = 'data:%s;base64,%s' % ('image/png', b64encode(header_blob))
    assert 'xlink:href="%s"></image>' % base_64_uri in svg_content
Ejemplo n.º 17
0
def test_generate_preview_with_additional_backgrounds(
    convert_svg_to_png_mock,
    write_svg_to_png_mock,
    resize_image_mock,
    pngcrush_image_mock,
    extract_colors_from_image_mock,
    index_addons_mock,
):
    write_svg_to_png_mock.side_effect = write_empty_png
    convert_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]

    theme_manifest = {
        'images': {
            'theme_frame': 'empty.png',
            'additional_backgrounds': ['weta_for_tiling.png'],
        },
        'colors': {
            'textcolor': '#123456',
            # Just textcolor, to test the template defaults and fallbacks.
        },
        'properties': {
            'additional_backgrounds_alignment': ['top'],
            'additional_backgrounds_tiling': ['repeat-x'],
        },
    }
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(
        settings.ROOT,
        'src/olympia/devhub/tests/addons/static_theme_tiled.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    # for svg preview we write the svg twice, 1st with write_svg, later with convert_svg
    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert convert_svg_to_png_mock.call_count == 1
    assert pngcrush_image_mock.call_count == 1

    # First check the firefox Preview is good
    firefox_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['firefox']['position'],
    )
    check_preview(
        firefox_preview,
        amo.THEME_PREVIEW_RENDERINGS['firefox'],
    )
    assert write_svg_to_png_mock.call_args_list[0][0][
        1] == firefox_preview.image_path
    check_thumbnail(
        firefox_preview,
        amo.THEME_PREVIEW_RENDERINGS['firefox'],
        firefox_preview.image_path,
        resize_image_mock.call_args_list[0],
        pngcrush_image_mock.call_args_list[0][0],
    )

    # And then the Preview used on AMO
    amo_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['amo']['position'],
    )
    check_preview(
        amo_preview,
        amo.THEME_PREVIEW_RENDERINGS['amo'],
    )
    assert convert_svg_to_png_mock.call_args_list[0][0][
        0] == amo_preview.image_path
    check_thumbnail(
        amo_preview,
        amo.THEME_PREVIEW_RENDERINGS['amo'],
        convert_svg_to_png_mock.call_args_list[0][0][1],
        resize_image_mock.call_args_list[1],
    )

    # These defaults are mostly defined in the xml template
    default_colors = (
        ('frame', 'fill',
         'rgba(229,230,232,1)'),  # amo.THEME_FRAME_COLOR_DEFAULT
        ('tab_background_text', 'fill',
         '#123456'),  # the only one defined in manifest
        ('bookmark_text', 'fill',
         '#123456'),  # should default to tab_background_text
        ('toolbar_field', 'fill', 'rgba(255,255,255,1)'),
        ('toolbar_field_text', 'fill', ''),
        ('tab_line', 'stroke', 'rgba(0,0,0,0.25)'),
        ('tab_selected toolbar', 'fill', 'rgba(255,255,255,0.6)'),
    )
    colors = [
        f'class="{key} {prop}" {prop}="{color}"'
        for (key, prop, color) in default_colors
    ]

    firefox_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    interim_amo_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    with open(amo_preview.image_path) as svg:
        amo_svg = svg.read()
    check_render_additional(force_str(firefox_svg), 680, colors)
    check_render_additional(force_str(interim_amo_svg), 720,
                            transparent_colors)
    check_render(
        force_str(amo_svg),
        'empty.jpg',
        92,
        'xMaxYMin slice',
        'image/jpeg',
        True,
        colors,
        720,
        92,
        720,
    )

    index_addons_mock.assert_called_with([addon.id])
Ejemplo n.º 18
0
def test_generate_static_theme_preview_with_alternative_properties(
    convert_svg_to_png_mock,
    write_svg_to_png_mock,
    resize_image_mock,
    pngcrush_image_mock,
    extract_colors_from_image_mock,
    index_addons_mock,
    manifest_images,
    manifest_colors,
    svg_colors,
):
    write_svg_to_png_mock.side_effect = write_empty_png
    convert_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]
    theme_manifest = {
        'images': manifest_images,
        'colors': manifest_colors,
    }
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(HEADER_ROOT, 'theme_images.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    # for svg preview we write the svg twice, 1st with write_svg, later with convert_svg
    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert convert_svg_to_png_mock.call_count == 1
    assert pngcrush_image_mock.call_count == 1

    # First check the firefox Preview is good
    firefox_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['firefox']['position'],
    )
    check_preview(
        firefox_preview,
        amo.THEME_PREVIEW_RENDERINGS['firefox'],
    )
    assert write_svg_to_png_mock.call_args_list[0][0][
        1] == firefox_preview.image_path
    check_thumbnail(
        firefox_preview,
        amo.THEME_PREVIEW_RENDERINGS['firefox'],
        firefox_preview.image_path,
        resize_image_mock.call_args_list[0],
        pngcrush_image_mock.call_args_list[0][0],
    )

    # And then the Preview used on AMO
    amo_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['amo']['position'],
    )
    check_preview(
        amo_preview,
        amo.THEME_PREVIEW_RENDERINGS['amo'],
    )
    assert convert_svg_to_png_mock.call_args_list[0][0][
        0] == amo_preview.image_path
    check_thumbnail(
        amo_preview,
        amo.THEME_PREVIEW_RENDERINGS['amo'],
        convert_svg_to_png_mock.call_args_list[0][0][1],
        resize_image_mock.call_args_list[1],
    )

    colors = [
        'class="%(field)s %(prop)s" %(prop)s="%(color)s"' % {
            'field': key,
            'prop': 'stroke' if key == 'tab_line' else 'fill',
            'color': color,
        } for (key, color) in svg_colors.items()
    ]

    firefox_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    interim_amo_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    with open(amo_preview.image_path) as svg:
        amo_svg = svg.read()
    check_render(
        force_str(firefox_svg),
        'transparent.gif',
        1,
        'xMaxYMin meet',
        'image/gif',
        True,
        colors,
        680,
        92,
        680,
    )
    check_render(
        force_str(interim_amo_svg),
        'transparent.gif',
        1,
        'xMaxYMin meet',
        'image/gif',
        True,
        transparent_colors,
        720,
        92,
        720,
    )
    check_render(
        force_str(amo_svg),
        'empty.jpg',
        92,
        'xMaxYMin slice',
        'image/jpeg',
        True,
        colors,
        720,
        92,
        720,
    )
Ejemplo n.º 19
0
def test_generate_static_theme_preview(
    convert_svg_to_png_mock,
    write_svg_to_png_mock,
    resize_image_mock,
    pngcrush_image_mock,
    extract_colors_from_image_mock,
    index_addons_mock,
    header_url,
    header_height,
    preserve_aspect_ratio,
    mimetype,
    valid_img,
):
    write_svg_to_png_mock.side_effect = write_empty_png
    convert_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]
    theme_manifest = {
        'images': {},
        'colors': {
            'frame': '#918e43',
            'tab_background_text': '#3deb60',
            'bookmark_text': '#b5ba5b',
            'toolbar_field': '#cc29cc',
            'toolbar_field_text': '#17747d',
            'tab_line': '#00db12',
            'tab_selected': '#40df39',
        },
    }
    if header_url is not None:
        theme_manifest['images']['theme_frame'] = header_url
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(HEADER_ROOT, 'theme_images.zip')
    copy_stored_file(zip_file, destination)
    # existing previews should be deleted if they exist
    existing_preview = VersionPreview.objects.create(
        version=addon.current_version)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)
    # check that it was deleted
    assert not VersionPreview.objects.filter(id=existing_preview.id).exists()
    assert VersionPreview.objects.filter(
        version=addon.current_version).count() == 2

    # for svg preview we write the svg twice, 1st with write_svg, later with convert_svg
    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert convert_svg_to_png_mock.call_count == 1
    assert pngcrush_image_mock.call_count == 1

    # First check the firefox Preview is good
    firefox_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['firefox']['position'],
    )
    check_preview(
        firefox_preview,
        amo.THEME_PREVIEW_RENDERINGS['firefox'],
    )
    assert write_svg_to_png_mock.call_args_list[0][0][
        1] == firefox_preview.image_path
    check_thumbnail(
        firefox_preview,
        amo.THEME_PREVIEW_RENDERINGS['firefox'],
        firefox_preview.image_path,
        resize_image_mock.call_args_list[0],
        pngcrush_image_mock.call_args_list[0][0],
    )

    # And then Preview used on AMO
    amo_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['amo']['position'],
    )
    check_preview(
        amo_preview,
        amo.THEME_PREVIEW_RENDERINGS['amo'],
    )
    assert convert_svg_to_png_mock.call_args_list[0][0][
        0] == amo_preview.image_path
    check_thumbnail(
        amo_preview,
        amo.THEME_PREVIEW_RENDERINGS['amo'],
        convert_svg_to_png_mock.call_args_list[0][0][1],
        resize_image_mock.call_args_list[1],
    )

    # Now check the svg renders
    firefox_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    interim_amo_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    with open(amo_preview.image_path) as svg:
        amo_svg = svg.read()
    preview_colors = {
        **theme_manifest['colors'],
        'tab_selected toolbar':
        theme_manifest['colors']['tab_selected'],
    }
    colors = [
        'class="%(field)s %(prop)s" %(prop)s="%(color)s"' % {
            'field': key,
            'prop': 'stroke' if key == 'tab_line' else 'fill',
            'color': color,
        } for (key, color) in preview_colors.items() if key != 'tab_selected'
    ]

    preserve_aspect_ratio = ((preserve_aspect_ratio, ) *
                             3 if not isinstance(preserve_aspect_ratio, tuple)
                             else preserve_aspect_ratio)
    check_render(
        force_str(firefox_svg),
        header_url,
        header_height,
        preserve_aspect_ratio[0],
        mimetype,
        valid_img,
        colors,
        680,
        92,
        680,
    )
    check_render(
        force_str(interim_amo_svg),
        header_url,
        header_height,
        preserve_aspect_ratio[1],
        mimetype,
        valid_img,
        transparent_colors,
        720,
        92,
        720,
    )
    check_render(
        force_str(amo_svg),
        'empty.jpg',
        92,
        'xMaxYMin slice',
        'image/jpeg',
        True,
        colors,
        720,
        92,
        720,
    )

    index_addons_mock.assert_called_with([addon.id])
Ejemplo n.º 20
0
def test_generate_preview_with_additional_backgrounds(
    write_svg_to_png_mock,
    resize_image_mock,
    pngcrush_image_mock,
    extract_colors_from_image_mock,
    index_addons_mock,
):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]

    theme_manifest = {
        'images': {
            'theme_frame': 'empty.png',
            'additional_backgrounds': ['weta_for_tiling.png'],
        },
        'colors': {
            'textcolor': '#123456',
            # Just textcolor, to test the template defaults and fallbacks.
        },
        'properties': {
            'additional_backgrounds_alignment': ['top'],
            'additional_backgrounds_tiling': ['repeat-x'],
        },
    }
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(
        settings.ROOT,
        'src/olympia/devhub/tests/addons/static_theme_tiled.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert pngcrush_image_mock.call_count == 2

    # First check the firefox Preview is good
    firefox_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['firefox']['position'],
    )
    check_preview(
        firefox_preview,
        amo.THEME_PREVIEW_RENDERINGS['firefox'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0],
        pngcrush_image_mock.call_args_list[0][0],
    )

    # And then the Preview used on AMO
    amo_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['amo']['position'],
    )
    check_preview(
        amo_preview,
        amo.THEME_PREVIEW_RENDERINGS['amo'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1],
        pngcrush_image_mock.call_args_list[1][0],
    )

    # These defaults are mostly defined in the xml template
    default_colors = {
        'frame': 'rgba(229,230,232,1)',  # amo.THEME_FRAME_COLOR_DEFAULT
        'tab_background_text': '#123456',  # the only one defined in 'manifest'
        'bookmark_text': '#123456',  # should default to tab_background_text
        'toolbar_field': 'rgba(255,255,255,1)',
        'toolbar_field_text': '',
        'tab_line': 'rgba(0,0,0,0.25)',
        'tab_selected': 'rgba(0,0,0,0)',
    }
    colors = [
        'class="%s" fill="%s"' % (key, color)
        for (key, color) in default_colors.items()
    ]

    firefox_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    amo_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    check_render_additional(force_str(firefox_svg), 680, colors)
    check_render_additional(force_str(amo_svg), 720, colors)

    index_addons_mock.assert_called_with([addon.id])
Ejemplo n.º 21
0
def test_generate_static_theme_preview_with_alternative_properties(
    write_svg_to_png_mock,
    resize_image_mock,
    pngcrush_image_mock,
    extract_colors_from_image_mock,
    index_addons_mock,
    manifest_images,
    manifest_colors,
    svg_colors,
):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]
    theme_manifest = {
        'images': manifest_images,
        'colors': manifest_colors,
    }
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(HEADER_ROOT, 'theme_images.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert pngcrush_image_mock.call_count == 2

    # First check the firefox Preview is good
    firefox_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['firefox']['position'],
    )
    check_preview(
        firefox_preview,
        amo.THEME_PREVIEW_RENDERINGS['firefox'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0],
        pngcrush_image_mock.call_args_list[0][0],
    )

    # And then the Preview used on AMO
    amo_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['amo']['position'],
    )
    check_preview(
        amo_preview,
        amo.THEME_PREVIEW_RENDERINGS['amo'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1],
        pngcrush_image_mock.call_args_list[1][0],
    )

    colors = [
        'class="%s" fill="%s"' % (key, color)
        for (key, color) in svg_colors.items()
    ]

    firefox_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    amo_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    check_render(
        force_str(firefox_svg),
        'transparent.gif',
        1,
        'xMaxYMin meet',
        'image/gif',
        True,
        colors,
        680,
        92,
        680,
    )
    check_render(
        force_str(amo_svg),
        'transparent.gif',
        1,
        'xMaxYMin meet',
        'image/gif',
        True,
        colors,
        720,
        92,
        720,
    )
Ejemplo n.º 22
0
def test_generate_preview_with_additional_backgrounds(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock,
        extract_colors_from_image_mock, index_addons_mock):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]

    theme_manifest = {
        "images": {
            "theme_frame": "empty.png",
            "additional_backgrounds": ["weta_for_tiling.png"],
        },
        "colors": {
            "textcolor": "#123456",
            # Just textcolor, to test the template defaults and fallbacks.
        },
        "properties": {
            "additional_backgrounds_alignment": ["top"],
            "additional_backgrounds_tiling": ["repeat-x"],
        },
    }
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(
        settings.ROOT,
        'src/olympia/devhub/tests/addons/static_theme_tiled.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 3
    assert write_svg_to_png_mock.call_count == 3
    assert pngcrush_image_mock.call_count == 3

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(header_preview, amo.THEME_PREVIEW_SIZES['header'],
                  write_svg_to_png_mock.call_args_list[0][0],
                  resize_image_mock.call_args_list[0][0],
                  pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(list_preview, amo.THEME_PREVIEW_SIZES['list'],
                  write_svg_to_png_mock.call_args_list[1][0],
                  resize_image_mock.call_args_list[1][0],
                  pngcrush_image_mock.call_args_list[1][0])

    # And finally the new single Preview
    single_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['single']['position'])
    check_preview(single_preview, amo.THEME_PREVIEW_SIZES['single'],
                  write_svg_to_png_mock.call_args_list[2][0],
                  resize_image_mock.call_args_list[2][0],
                  pngcrush_image_mock.call_args_list[2][0])

    # These defaults are mostly defined in the xml template
    default_colors = {
        "frame": "rgba(229,230,232,1)",  # amo.THEME_FRAME_COLOR_DEFAULT
        "tab_background_text": "#123456",  # the only one defined in 'manifest'
        "bookmark_text": "#123456",  # should default to tab_background_text
        "toolbar_field": "rgba(255,255,255,1)",
        "toolbar_field_text": "",
        "tab_line": "rgba(0,0,0,0.25)",
        "tab_selected": "rgba(0,0,0,0)",
    }
    colors = [
        'class="%s" fill="%s"' % (key, color)
        for (key, color) in default_colors.items()
    ]

    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    single_svg = write_svg_to_png_mock.call_args_list[2][0][0]
    check_render_additional(force_text(header_svg), 680, colors)
    check_render_additional(force_text(list_svg), 760, colors)
    check_render_additional(force_text(single_svg), 720, colors)

    index_addons_mock.assert_called_with([addon.id])
Ejemplo n.º 23
0
def test_generate_static_theme_preview_with_chrome_properties(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock,
        extract_colors_from_image_mock, index_addons_mock):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]
    theme_manifest = {
        "images": {
            "theme_frame": "transparent.gif"
        },
        "colors": {
            "frame": [123, 45, 67],  # 'accentcolor'
            "tab_background_text": [9, 87, 65],  # 'textcolor'
            "bookmark_text": [0, 0, 0],  # 'toolbar_text'
        }
    }
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(HEADER_ROOT, 'theme_images.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 3
    assert write_svg_to_png_mock.call_count == 3
    assert pngcrush_image_mock.call_count == 3

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(header_preview, amo.THEME_PREVIEW_SIZES['header'],
                  write_svg_to_png_mock.call_args_list[0][0],
                  resize_image_mock.call_args_list[0][0],
                  pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(list_preview, amo.THEME_PREVIEW_SIZES['list'],
                  write_svg_to_png_mock.call_args_list[1][0],
                  resize_image_mock.call_args_list[1][0],
                  pngcrush_image_mock.call_args_list[1][0])

    # And finally the new single Preview
    single_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['single']['position'])
    check_preview(single_preview, amo.THEME_PREVIEW_SIZES['single'],
                  write_svg_to_png_mock.call_args_list[2][0],
                  resize_image_mock.call_args_list[2][0],
                  pngcrush_image_mock.call_args_list[2][0])

    colors = []
    # check each of our colors above was converted to css codes
    chrome_colors = {
        'bookmark_text': 'toolbar_text',
        'frame': 'accentcolor',
        'tab_background_text': 'textcolor',
    }
    for (chrome_prop, firefox_prop) in chrome_colors.items():
        color_list = theme_manifest['colors'][chrome_prop]
        color = 'rgb(%s,%s,%s)' % tuple(color_list)
        colors.append('class="%s" fill="%s"' % (firefox_prop, color))

    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    single_svg = write_svg_to_png_mock.call_args_list[2][0][0]
    check_render(force_text(header_svg), 'transparent.gif', 1, 'xMaxYMin meet',
                 'image/gif', True, colors, 680, 92, 680)
    check_render(force_text(list_svg), 'transparent.gif', 1, 'xMaxYMin meet',
                 'image/gif', True, colors, 760, 92, 760)
    check_render(force_text(single_svg), 'transparent.gif', 1, 'xMaxYMin meet',
                 'image/gif', True, colors, 720, 92, 720)
Ejemplo n.º 24
0
def test_generate_static_theme_preview_with_alternative_properties(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock,
        extract_colors_from_image_mock, index_addons_mock,
        manifest_images, manifest_colors, svg_colors):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [
        {'h': 9, 's': 8, 'l': 7, 'ratio': 0.6}
    ]
    theme_manifest = {
        "images": manifest_images,
        "colors": manifest_colors,
    }
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(HEADER_ROOT, 'theme_images.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 3
    assert write_svg_to_png_mock.call_count == 3
    assert pngcrush_image_mock.call_count == 3

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(
        header_preview, amo.THEME_PREVIEW_SIZES['header'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0][0],
        pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(
        list_preview, amo.THEME_PREVIEW_SIZES['list'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1][0],
        pngcrush_image_mock.call_args_list[1][0])

    # And finally the new single Preview
    single_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['single']['position'])
    check_preview(
        single_preview, amo.THEME_PREVIEW_SIZES['single'],
        write_svg_to_png_mock.call_args_list[2][0],
        resize_image_mock.call_args_list[2][0],
        pngcrush_image_mock.call_args_list[2][0])

    colors = ['class="%s" fill="%s"' % (key, color)
              for (key, color) in svg_colors.items()]

    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    single_svg = write_svg_to_png_mock.call_args_list[2][0][0]
    check_render(force_text(header_svg), 'transparent.gif', 1,
                 'xMaxYMin meet', 'image/gif', True, colors, 680, 92, 680)
    check_render(force_text(list_svg), 'transparent.gif', 1,
                 'xMaxYMin meet', 'image/gif', True, colors, 760, 92, 760)
    check_render(force_text(single_svg), 'transparent.gif', 1,
                 'xMaxYMin meet', 'image/gif', True, colors, 720, 92, 720)
Ejemplo n.º 25
0
def test_generate_static_theme_preview_with_alternative_properties(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock,
        extract_colors_from_image_mock, index_addons_mock, manifest_images,
        manifest_colors, svg_colors):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]
    theme_manifest = {
        "images": manifest_images,
        "colors": manifest_colors,
    }
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(HEADER_ROOT, 'theme_images.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 3
    assert write_svg_to_png_mock.call_count == 3
    assert pngcrush_image_mock.call_count == 3

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(header_preview, amo.THEME_PREVIEW_SIZES['header'],
                  write_svg_to_png_mock.call_args_list[0][0],
                  resize_image_mock.call_args_list[0][0],
                  pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(list_preview, amo.THEME_PREVIEW_SIZES['list'],
                  write_svg_to_png_mock.call_args_list[1][0],
                  resize_image_mock.call_args_list[1][0],
                  pngcrush_image_mock.call_args_list[1][0])

    # And finally the new single Preview
    single_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['single']['position'])
    check_preview(single_preview, amo.THEME_PREVIEW_SIZES['single'],
                  write_svg_to_png_mock.call_args_list[2][0],
                  resize_image_mock.call_args_list[2][0],
                  pngcrush_image_mock.call_args_list[2][0])

    colors = [
        'class="%s" fill="%s"' % (key, color)
        for (key, color) in svg_colors.items()
    ]

    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    single_svg = write_svg_to_png_mock.call_args_list[2][0][0]
    check_render(force_text(header_svg), 'transparent.gif', 1, 'xMaxYMin meet',
                 'image/gif', True, colors, 680, 92, 680)
    check_render(force_text(list_svg), 'transparent.gif', 1, 'xMaxYMin meet',
                 'image/gif', True, colors, 760, 92, 760)
    check_render(force_text(single_svg), 'transparent.gif', 1, 'xMaxYMin meet',
                 'image/gif', True, colors, 720, 92, 720)
Ejemplo n.º 26
0
def test_generate_static_theme_preview(
        write_svg_to_png_mock, resize_image_mock, pngcrush_image_mock,
        extract_colors_from_image_mock, index_addons_mock,
        header_url, header_height, preserve_aspect_ratio, mimetype, valid_img):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [
        {'h': 9, 's': 8, 'l': 7, 'ratio': 0.6}
    ]
    theme_manifest = {
        "images": {
        },
        "colors": {
            "frame": "#918e43",
            "tab_background_text": "#3deb60",
            "bookmark_text": "#b5ba5b",
            "toolbar_field": "#cc29cc",
            "toolbar_field_text": "#17747d",
            "tab_line": "#00db12",
            "tab_selected": "#40df39",
        }
    }
    if header_url is not None:
        theme_manifest['images']['theme_frame'] = header_url
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(HEADER_ROOT, 'theme_images.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 3
    assert write_svg_to_png_mock.call_count == 3
    assert pngcrush_image_mock.call_count == 3

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(
        header_preview, amo.THEME_PREVIEW_SIZES['header'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0][0],
        pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(
        list_preview, amo.THEME_PREVIEW_SIZES['list'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1][0],
        pngcrush_image_mock.call_args_list[1][0])

    # And finally the new single Preview
    single_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['single']['position'])
    check_preview(
        single_preview, amo.THEME_PREVIEW_SIZES['single'],
        write_svg_to_png_mock.call_args_list[2][0],
        resize_image_mock.call_args_list[2][0],
        pngcrush_image_mock.call_args_list[2][0])

    # Now check the svg renders
    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    single_svg = write_svg_to_png_mock.call_args_list[2][0][0]
    colors = ['class="%s" fill="%s"' % (key, color)
              for (key, color) in theme_manifest['colors'].items()]
    preserve_aspect_ratio = (
        (preserve_aspect_ratio, ) * 3
        if not isinstance(preserve_aspect_ratio, tuple)
        else preserve_aspect_ratio)
    check_render(force_text(header_svg), header_url, header_height,
                 preserve_aspect_ratio[0], mimetype, valid_img, colors,
                 680, 92, 680)
    check_render(force_text(list_svg), header_url, header_height,
                 preserve_aspect_ratio[1], mimetype, valid_img, colors,
                 760, 92, 760)
    check_render(force_text(single_svg), header_url, header_height,
                 preserve_aspect_ratio[2], mimetype, valid_img, colors,
                 720, 92, 720)

    index_addons_mock.assert_called_with([addon.id])
Ejemplo n.º 27
0
def test_generate_static_theme_preview(write_svg_to_png_mock,
                                       resize_image_mock, pngcrush_image_mock,
                                       extract_colors_from_image_mock,
                                       index_addons_mock, header_url,
                                       header_height, preserve_aspect_ratio,
                                       mimetype, valid_img):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]
    theme_manifest = {
        "images": {},
        "colors": {
            "frame": "#918e43",
            "tab_background_text": "#3deb60",
            "bookmark_text": "#b5ba5b",
            "toolbar_field": "#cc29cc",
            "toolbar_field_text": "#17747d",
            "tab_line": "#00db12",
            "tab_selected": "#40df39",
        }
    }
    if header_url is not None:
        theme_manifest['images']['theme_frame'] = header_url
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(HEADER_ROOT, 'theme_images.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 3
    assert write_svg_to_png_mock.call_count == 3
    assert pngcrush_image_mock.call_count == 3

    # First check the header Preview is good
    header_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['header']['position'])
    check_preview(header_preview, amo.THEME_PREVIEW_SIZES['header'],
                  write_svg_to_png_mock.call_args_list[0][0],
                  resize_image_mock.call_args_list[0][0],
                  pngcrush_image_mock.call_args_list[0][0])

    # Then the list Preview
    list_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['list']['position'])
    check_preview(list_preview, amo.THEME_PREVIEW_SIZES['list'],
                  write_svg_to_png_mock.call_args_list[1][0],
                  resize_image_mock.call_args_list[1][0],
                  pngcrush_image_mock.call_args_list[1][0])

    # And finally the new single Preview
    single_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_SIZES['single']['position'])
    check_preview(single_preview, amo.THEME_PREVIEW_SIZES['single'],
                  write_svg_to_png_mock.call_args_list[2][0],
                  resize_image_mock.call_args_list[2][0],
                  pngcrush_image_mock.call_args_list[2][0])

    # Now check the svg renders
    header_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    list_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    single_svg = write_svg_to_png_mock.call_args_list[2][0][0]
    colors = [
        'class="%s" fill="%s"' % (key, color)
        for (key, color) in theme_manifest['colors'].items()
    ]
    preserve_aspect_ratio = ((preserve_aspect_ratio, ) *
                             3 if not isinstance(preserve_aspect_ratio, tuple)
                             else preserve_aspect_ratio)
    check_render(force_text(header_svg), header_url, header_height,
                 preserve_aspect_ratio[0], mimetype, valid_img, colors, 680,
                 92, 680)
    check_render(force_text(list_svg), header_url, header_height,
                 preserve_aspect_ratio[1], mimetype, valid_img, colors, 760,
                 92, 760)
    check_render(force_text(single_svg), header_url, header_height,
                 preserve_aspect_ratio[2], mimetype, valid_img, colors, 720,
                 92, 720)

    index_addons_mock.assert_called_with([addon.id])
Ejemplo n.º 28
0
def test_generate_static_theme_preview(
    write_svg_to_png_mock,
    resize_image_mock,
    pngcrush_image_mock,
    extract_colors_from_image_mock,
    index_addons_mock,
    header_url,
    header_height,
    preserve_aspect_ratio,
    mimetype,
    valid_img,
):
    write_svg_to_png_mock.return_value = True
    extract_colors_from_image_mock.return_value = [{
        'h': 9,
        's': 8,
        'l': 7,
        'ratio': 0.6
    }]
    theme_manifest = {
        'images': {},
        'colors': {
            'frame': '#918e43',
            'tab_background_text': '#3deb60',
            'bookmark_text': '#b5ba5b',
            'toolbar_field': '#cc29cc',
            'toolbar_field_text': '#17747d',
            'tab_line': '#00db12',
            'tab_selected': '#40df39',
        },
    }
    if header_url is not None:
        theme_manifest['images']['theme_frame'] = header_url
    addon = addon_factory()
    destination = addon.current_version.all_files[0].current_file_path
    zip_file = os.path.join(HEADER_ROOT, 'theme_images.zip')
    copy_stored_file(zip_file, destination)
    generate_static_theme_preview(theme_manifest, addon.current_version.pk)

    assert resize_image_mock.call_count == 2
    assert write_svg_to_png_mock.call_count == 2
    assert pngcrush_image_mock.call_count == 2

    # First check the firefox Preview is good
    firefox_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['firefox']['position'],
    )
    check_preview(
        firefox_preview,
        amo.THEME_PREVIEW_RENDERINGS['firefox'],
        write_svg_to_png_mock.call_args_list[0][0],
        resize_image_mock.call_args_list[0],
        pngcrush_image_mock.call_args_list[0][0],
    )

    # And then Preview used on AMO
    amo_preview = VersionPreview.objects.get(
        version=addon.current_version,
        position=amo.THEME_PREVIEW_RENDERINGS['amo']['position'],
    )
    check_preview(
        amo_preview,
        amo.THEME_PREVIEW_RENDERINGS['amo'],
        write_svg_to_png_mock.call_args_list[1][0],
        resize_image_mock.call_args_list[1],
        pngcrush_image_mock.call_args_list[1][0],
    )

    # Now check the svg renders
    firefox_svg = write_svg_to_png_mock.call_args_list[0][0][0]
    amo_svg = write_svg_to_png_mock.call_args_list[1][0][0]
    colors = [
        'class="%s" fill="%s"' % (key, color)
        for (key, color) in theme_manifest['colors'].items()
    ]
    preserve_aspect_ratio = ((preserve_aspect_ratio, ) *
                             3 if not isinstance(preserve_aspect_ratio, tuple)
                             else preserve_aspect_ratio)
    check_render(
        force_str(firefox_svg),
        header_url,
        header_height,
        preserve_aspect_ratio[0],
        mimetype,
        valid_img,
        colors,
        680,
        92,
        680,
    )
    check_render(
        force_str(amo_svg),
        header_url,
        header_height,
        preserve_aspect_ratio[1],
        mimetype,
        valid_img,
        colors,
        720,
        92,
        720,
    )

    index_addons_mock.assert_called_with([addon.id])